Module: ColumnSync::Migration

Defined in:
lib/column_sync/migration.rb

Instance Method Summary collapse

Instance Method Details

#sync_columns(columns) ⇒ Object



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

def sync_columns(columns)
  FileUtils.mkdir_p("db/functions")
  FileUtils.mkdir_p("db/triggers")

  service = Service.new(columns)

  each_function(service) { |name| create_function(name) }
  each_trigger(service) { |name, table_name| create_trigger(name, on: table_name) }
end

#unsync_columns(columns) ⇒ Object



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

def unsync_columns(columns)
  service = Service.new(columns)

  each_trigger(service) { |name, table_name| drop_trigger(name, on: table_name) }
  each_function(service) { |name| drop_function(name) }
end