Class: Pakyow::Data::Sources::Relational::Migrator

Inherits:
Object
  • Object
show all
Defined in:
lib/pakyow/data/sources/relational/migrator.rb

Direct Known Subclasses

Adapters::Sql::Migrator

Instance Method Summary collapse

Constructor Details

#initialize(connection, sources: []) ⇒ Migrator

Returns a new instance of Migrator.



8
9
10
# File 'lib/pakyow/data/sources/relational/migrator.rb', line 8

def initialize(connection, sources: [])
  @connection, @sources = connection, sources
end

Instance Method Details

#auto_migrate!Object



12
13
14
15
16
# File 'lib/pakyow/data/sources/relational/migrator.rb', line 12

def auto_migrate!
  if @sources.any?
    migrate!(automator)
  end
end

#finalize!Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pakyow/data/sources/relational/migrator.rb', line 18

def finalize!
  if @sources.any?
    migrator = finalizer
    migrate!(migrator)

    # Return the migrations that need to be created.
    #
    prefix = Time.now.strftime("%Y%m%d%H%M%S").to_i
    migrator.migrations.each_with_object({}) { |(action, content), migrations|
      migrations["#{prefix}_#{action}.rb"] = content

      # Ensure that migration files appear in the correct order.
      #
      prefix += 1
    }
  else
    {}
  end
end