Module: SharedMigration

Defined in:
lib/shared_migration.rb

Overview

Methods to DRY out migrations

Instance Method Summary collapse

Instance Method Details

#add_discard(table_name:) ⇒ Object


15
16
17
18
19
20
# File 'lib/shared_migration.rb', line 15

def add_discard(table_name:)
  raise MissingTableNameException.new table_name if table_name.blank?

  add_column table_name, :discarded_at, :datetime
  add_index table_name, :discarded_at
end

#create_name_table(table_name:) ⇒ Object


5
6
7
8
9
10
11
12
13
# File 'lib/shared_migration.rb', line 5

def create_name_table(table_name:)
  raise MissingTableNameException.new table_name if table_name.blank?

  create_table table_name do |tname|
    tname.string :name, null: false
    tname.timestamps null: false, default: -> { 'CURRENT_TIMESTAMP' }
  end
  add_index table_name, :name, unique: true, name: %(index_by_#{table_name})
end