Sha256: a1fd85fbfa14ff569c1768d70b7a1fe507e1423242475aad7979f9d248f8d1da

Contents?: true

Size: 1.28 KB

Versions: 4

Compression:

Stored size: 1.28 KB

Contents

class McflyMigration < ActiveRecord::Migration[4.2]
  INSERT_TRIG, UPDATE_TRIG, UPDATE_APPEND_ONLY_TRIG, DELETE_TRIG, CONSTRAINT =
    %w{
        insert_trig
        update_trig
        update_append_only_trig
        delete_trig
        constraint
    }.map { |f|
    File.read(File.dirname(__FILE__) + "/#{f}.sql")
  }

  TRIGS = [INSERT_TRIG, UPDATE_TRIG, DELETE_TRIG]

  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

  # TODO: Remove this in 4.0 since we can check direction
  def migrate(direction)
    @dir = direction
    super
  end

  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
end

class McflyAppendOnlyMigration < McflyMigration
  # append-only update trigger disallows updates
  TRIGS = [INSERT_TRIG, UPDATE_APPEND_ONLY_TRIG, DELETE_TRIG]
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mcfly-0.1.0 lib/mcfly/migration.rb
mcfly-0.0.22 lib/mcfly/migration.rb
mcfly-0.0.21 lib/mcfly/migration.rb
mcfly-0.0.20 lib/mcfly/migration.rb