Note that there are some explanatory texts on larger screens.

plurals
  1. PORails migrations for postgreSQL schemas
    primarykey
    data
    text
    <p>I'm working on a multi-tenant rails application using PostgreSQL schemas for different clients. Rails migrations don't work with multiple schemas out of the box, so I made the following rake task to migrate all schemas and it seems to work. My question is if others have implemented better and more elegant solutions. I would also be really happy with a good tutorial including rails code examples for PostgreSQL using multiple schemas. So far I have only found a good presentation on the subject <a href="http://aac2009.confreaks.com/06-feb-2009-14-30-writing-multi-tenant-applications-in-rails-guy-naor.html" rel="noreferrer">http://aac2009.confreaks.com/06-feb-2009-14-30-writing-multi-tenant-applications-in-rails-guy-naor.html</a> and an example of what I'm aiming for tomayko.com/writings/rails-multiple-connections</p> <pre><code>desc 'Migrates all postgres schemas' task :schemas do # get all schemas env = "#{RAILS_ENV}" config = YAML::load(File.open('config/database.yml')) ActiveRecord::Base.establish_connection(config[env]) schemas = ActiveRecord::Base.connection.select_values("select * from pg_namespace where nspname != 'information_schema' AND nspname NOT LIKE 'pg%'") puts "Migrate schemas: #{schemas.inspect}" # migrate each schema schemas.each do |schema| puts "Migrate schema: #{schema}" config = YAML::load(File.open('config/database.yml')) config[env]["schema_search_path"] = schema ActiveRecord::Base.establish_connection(config[env]) ActiveRecord::Base.logger = Logger.new(STDOUT) ActiveRecord::Migrator.migrate('db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil) end end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload