Avro schema resolution with different namespace - avro

Is it possible to change the namespace of a schema once it is published?

In Java at least, the answer is generally, yes. But as of 1.8.0, not if the record is within a union type.

Related

How to make rake db:migrate dump the right schema when we use Scenic to manage views [duplicate]

Is the structure just a sql version of the db while the schema is a Rails version of the db? When would you want to load either? Or does it make a difference?
The schema file is the Rails version of your db and doesn't contain any db specific stuff like, views, triggers, and so on.
db/schema.rb cannot express database specific items such as triggers,
sequences, stored procedures or check constraints, etc. Please note
that while custom SQL statements can be run in migrations, these
statements cannot be reconstituted by the schema dumper. If you are
using features like this, then you should set the schema format to
:sql.
http://edgeguides.rubyonrails.org/active_record_migrations.html#schema-dumping-and-you
When would you use one over the other depends on whether you have db specific stuff that you need. If all you use are the basic tables, with indexes and primary and foreign keys you are good to go with schema files.
In my opinion however I always use structure.sql since I always use some db specific things.
You can change what format you want to use by changing this in your config/application.rb file.
config.active_record.schema_format = :sql # default is :ruby

neo4jrb DeprecatedSchemaDefinitionError

I've a problem with Neo4jrb 8.1.1, Rails 5.1.1, Neo4j 3.2.0 CE
I have a City model with an Int id, the DB is read only with data imported from csv files.
What should I declare to get rid of the error?
So far, I thought that declaring
id_property :id
property :name
would be fine but it doesn't work.
Overall, I'm annoyed with these new migrations files because the Neo4J DB is already done, I'm not supposed to write or modify indexes or constraints.
What's the error message you're seeing? I imagine you can solve the issue by creating an initializer and manually adding the relevant constraint(s) to the ModelSchema. Something like Neo4j::ModelSchema.add_defined_constraint(City, :id). It's also possible that this could be done inside the Model itself. Some experimentation should solve the problem.
See the source code for more info:
https://github.com/neo4jrb/neo4j/blob/8.1.x/lib/neo4j/model_schema.rb
http://www.rubydoc.info/gems/neo4j/Neo4j/ModelSchema

How to enable contrib modules on Heroku Postgres database

I'm trying to use contrib modules in the new Postgres 9 shared databases on Heroku. More specifically, the pg_trgm and fuzzystrmatch modules. In the documentation it says
In addition, many complimentary extensions are available such as
fuzzystrmatch, pg_trgm, and unaccent.
I can't seem to find any documentation on HOW to actually enable these modules on a shared Heroku database. See answer below.
NOTE:
I tried adding them by connecting to the database with
heroku pg:psql HEROKU_POSTGRESQL_BROWN
and running
create extension pg_trgm
create extension fuzzystrmatch
but after trying to use it with
SELECT levenshtein('tests', 'test');
it still said
ERROR: function levenshtein(unknown, unknown) does not existLINE 1: SELECT levenshtein('tests', 'test');
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
Anybody know why this happens?
Found answer here while scouring Stack Overflow. Don't know why it didn't come up in any of my Google searches. Going to leave the question here if anybody else uses the same wording to search for this.
To enable modules, you need to add them to a migration as follows:
def up
execute "create extension fuzzystrmatch"
execute "create extension pg_trgm"
end
In newer versions of Rails it should be sufficient to do:
def change
enable_extension "fuzzystrmatch"
enable_extension "pg_trgm"
end
If you need to write up and down methods, the corresponding method to enable_extension is disable_extension.

How to set transaction isolation level using ActiveRecord connection?

I need to manage transaction isolation level on a per-transaction basis in a way portable across databases (SQLite, PostgreSQL, MySQL at least).
I know I can do it manually, like that:
User.connection.execute('SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE')
...but I would expect something like:
User.isolation_level( :serializable ) do
# ...
end
This functionality is supported by ActiveRecord itself:
MyRecord.transaction(isolation: :read_committed) do
# do your transaction work
end
It supports the ANSI SQL isolation levels:
:read_uncommitted
:read_committed
:repeatable_read
:serializable
This method is available since Rails 4, it was unavailable when the OP asked the question. But for any decently modern Rails application this should be the way to go.
There was no gem available so I developed one (MIT): https://github.com/qertoip/transaction_isolation
Looks Rails4 would have the feature out of box:
https://github.com/rails/rails/commit/392eeecc11a291e406db927a18b75f41b2658253

How to set PostgreSQL table names in Rails with schema information?

I have to connect my rails app in a legacy Postgre database. It uses schemas so in a SQL its is common to use something like
SELECT * FROM "Financial".budget
I want to write a Budget model but I don't know how to set the table name in this case. I've tried the following:
set_table_name 'budget'
set_table_name '"Financial".budget'
None have worket.
ActiveRecord::Base.establish_connection(
:schema_search_path => 'Financial,public'
)
If you're using Postgres, the above is probably "good enough" for most situations.
I had similar issue with Oracle adapter. By default ActiveRecord always quotes table names in SQL and therefore if you specify
set_table_name "Financial.budget"
then generated SQL will be
SELECT * FROM "Financial.budget"
which will not work.
To solve this issue you need to monkey patch PostgreSQL adapter. Put into your environment.rb or in separate initializer the following code:
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do
# abstract_adapter calls quote_column_name from quote_table_name, so prevent that
def quote_table_name(name)
name
end
end
Now you should define in your model class
set_table_name "Financial.budget"
and generated SQL will be
SELECT * FROM Financial.budget
Now, this bug seems to be solved in 2-3-stable. Take a look at this post
Look at your logs -- what SQL is Rails generating with your various options?
set_table_name "Financial.budget"
Perhaps extending the search path with your schema will help you?
SET SEARCH_PATH TO "Financial", public;
Then you could write your query unqualified without the schema:
SELECT * FROM budget;
We designed a gem to make ActiveRecord work with PostgreSQL. Here is a small usage example:
http://greyblake.com/blog/2012/09/06/pg-power-activerecord-extension-for-postgresql/

Resources