Class: McflyMigration

Inherits:
Object
  • Object
show all
Defined in:
lib/mcfly/migration.rb

Direct Known Subclasses

McflyAppendOnlyMigration

Constant Summary collapse

TRIGS =
[INSERT_TRIG, UPDATE_TRIG, DELETE_TRIG]

Instance Method Summary collapse

Instance Method Details

#add_sql(table_name, include_const) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/mcfly/migration.rb', line 15

def add_sql(table_name, include_const)
  sql_list = self.class::TRIGS +
    (include_const ? [self.class::CONSTRAINT] : [])

  sql_list.each { |sql|
    execute sql % {table: table_name}
  }
end

#create_table(table_name, options = {}, &block) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/mcfly/migration.rb', line 30

def create_table(table_name, options = {}, &block)
  super { |t|
    t.integer :group_id, null: false
    # can't use created_at/updated_at as those are automatically
    # filled by ActiveRecord.
    t.timestamp :created_dt, null: false
    t.timestamp :obsoleted_dt, null: false
    t.references :user, null: false
    t.references :o_user
    block.call(t)
  }

  add_sql(table_name, true) if @dir == :up
end

#migrate(direction) ⇒ Object

TODO: Remove this in 4.0 since we can check direction



25
26
27
28
# File 'lib/mcfly/migration.rb', line 25

def migrate(direction)
  @dir = direction
  super
end