class MultitenancyTools::SchemaMigrator
{SchemaMigrator} is a wrapper around ActiveRecord::Migrator that executes all migrations inside a PostgreSQL schema.
Unfortunately this can only execute migrations using the global connection (the connection returned by ActiveRecord::Base.connection).
@example
migrator = MultitenancyTools::SchemaMigrator.new('my_schema', 'path/to/migrations') migrator.migrate
Public Class Methods
new(schema, migrations_path)
click to toggle source
@param schema [String] schema name @param migrations_path [String] path to the migrations files
# File lib/multitenancy_tools/schema_migrator.rb, line 16 def initialize(schema, migrations_path) @schema = schema @migrations_path = migrations_path end
Public Instance Methods
migrate()
click to toggle source
Executes all migrations.
# File lib/multitenancy_tools/schema_migrator.rb, line 22 def migrate run do ActiveRecord::Migrator.migrate(@migrations_path, nil) end end
rollback()
click to toggle source
Undo the latest migration.
# File lib/multitenancy_tools/schema_migrator.rb, line 29 def rollback run do ActiveRecord::Migrator.rollback(@migrations_path) end end
Private Instance Methods
run() { || ... }
click to toggle source
# File lib/multitenancy_tools/schema_migrator.rb, line 37 def run(&block) SchemaSwitcher.new(@schema, ActiveRecord::Base.connection).run do silence_stream(STDOUT) do yield end end end