Class: Storey::Migrator

Inherits:
Object
  • Object
show all
Defined in:
lib/storey/migrator.rb

Class Method Summary collapse

Class Method Details

.migrate(schema, options = {}) ⇒ Object



13
14
15
16
17
18
# File 'lib/storey/migrator.rb', line 13

def self.migrate(schema, options={})
  Storey.switch schema do
    puts "= Migrating #{schema}"
    active_record_migrate(options[:version])
  end
end

.migrate_all(options = {}) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/storey/migrator.rb', line 4

def self.migrate_all(options={})
  options[:version] = options[:version].to_i if options[:version]
  self.migrate 'public', options
  Dumper.dump
  Storey.schemas(public: false).each do |schema|
    self.migrate schema, options
  end
end

.rollback(schema, step = 1) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/storey/migrator.rb', line 33

def self.rollback(schema, step=1)
  Storey.switch schema do
    puts "= Rolling back `#{schema}` #{step} steps"
    ::ActiveRecord::Migrator.rollback(
      ::ActiveRecord::Migrator.migrations_paths,
      step
    )
  end
end

.rollback_all(step = 1) ⇒ Object



26
27
28
29
30
31
# File 'lib/storey/migrator.rb', line 26

def self.rollback_all(step=1)
  Storey.schemas.each do |schema_name|
    self.rollback(schema_name, step)
  end
  Dumper.dump
end

.run(direction, schema, version) ⇒ Object



20
21
22
23
24
# File 'lib/storey/migrator.rb', line 20

def self.run(direction, schema, version)
  Storey.switch schema do
    active_record_run(direction, version)
  end
end