Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ensuring search path on migrations

  • Loading branch information...
commit 9871882b717ac3f34ccd769a531947a307c3d601 1 parent b30626f
@dceballos dceballos authored
View
9 lib/roomer/helpers/postgres_helper.rb
@@ -112,6 +112,15 @@ def ensuring_schema(schema_name, &block)
end
end
+ def ensuring_schema_and_search_path(schema_name, &block)
+ raise ArgumentError.new("schema_name not present") unless schema_name
+ ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
+ create_schema(schema_name) unless schemas.include?(schema_name.to_s)
+ ActiveRecord::Base.connection.schema_search_path = "#{schema_name}, public"
+ ensure_schema_migrations
+ yield
+ end
+
def ensuring_tenant(tenant,&blk)
ensuring_schema(tenant.try(Roomer.tenant_schema_name_column)) do
Roomer.with_tenant(tenant,&blk)
View
9 lib/roomer/tasks/migrate.rake
@@ -7,7 +7,7 @@ namespace :roomer do
desc "Migrates the shared tables. Target specific version with VERSION=x"
task :migrate => :environment do
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
- ensuring_schema(Roomer.shared_schema_name) do
+ ensuring_schema_and_search_path(Roomer.shared_schema_name) do
ActiveRecord::Migrator.migrate(Roomer.shared_migrations_directory, version)
end
Roomer::Schema.dump(:shared)
@@ -30,7 +30,7 @@ namespace :roomer do
desc "Rolls back shared tables. Target specific version with STEP=x"
task :rollback => :environment do
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
- ensuring_schema(Roomer.shared_schema_name) do
+ ensuring_schema_and_search_path(Roomer.shared_schema_name) do
ActiveRecord::Migrator.rollback(Roomer.shared_migrations_directory, step)
end
Roomer::Schema.dump(:shared)
@@ -50,7 +50,7 @@ namespace :roomer do
desc "Display status of migrations for shared schema"
task :status => :environment do
- ensuring_schema(Roomer.shared_schema_name) do
+ ensuring_schema_and_search_path(Roomer.shared_schema_name) do
status(Roomer.shared_schema_name,Roomer.shared_migrations_directory)
end
end
@@ -100,8 +100,7 @@ namespace :roomer do
task :status do
Roomer.tenant_model.find(:all).each do |tenant|
ensuring_tenant(tenant) do
- ActiveRecord::Base.connection.schema_search_path = "#{tenant.schema_name},#{Roomer.shared_schema_name}"
- ensuring_schema(Roomer.current_tenant.schema_name) do
+ ensuring_schema_and_search_path(Roomer.current_tenant.schema_name) do
status(Roomer.current_tenant.schema_name,Roomer.tenanted_migrations_directory)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.