Sha256: 15ec90a314eea56c806e611b68c004d28ec97d4154b5844ac16ecd593f7115a0

Contents?: true

Size: 1.24 KB

Versions: 7

Compression:

Stored size: 1.24 KB

Contents

class McflyMigration < ActiveRecord::Migration
  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

7 entries across 7 versions & 1 rubygems

Version Path
mcfly-0.0.18 lib/mcfly/migration.rb
mcfly-0.0.17 lib/mcfly/migration.rb
mcfly-0.0.16 lib/mcfly/migration.rb
mcfly-0.0.15 lib/mcfly/migration.rb
mcfly-0.0.14 lib/mcfly/migration.rb
mcfly-0.0.13 lib/mcfly/migration.rb
mcfly-0.0.12 lib/mcfly/migration.rb