Module: Stagehand::Schema::Statements

Defined in:
lib/stagehand/schema/statements.rb

Instance Method Summary collapse

Instance Method Details

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

Ensure that developers are aware they need to make a determination of whether stagehand should track this table or not



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/stagehand/schema/statements.rb', line 5

def create_table(table_name, options = {})
  super
  options = options.symbolize_keys

  return if Database.connected_to_production? && !Stagehand::Configuration.single_connection?
  return Schema.send(:create_session_trigger) if options[:stagehand] == :commit_entries
  return if options[:stagehand] == false
  return if UNTRACKED_TABLES.include?(table_name)

  Schema.add_stagehand! :only => table_name
end

#drop_table(table_name) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/stagehand/schema/statements.rb', line 26

def drop_table(table_name, *)
  return super unless Schema.has_stagehand?(table_name) && table_exists?(Staging::CommitEntry.table_name)

  super
  Staging::CommitEntry.where(:table_name => table_name).delete_all
  Staging::Commit.empty.each(&:destroy)
end

#rename_table(old_table_name, new_table_name) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/stagehand/schema/statements.rb', line 17

def rename_table(old_table_name, new_table_name, *)
  return super unless Schema.has_stagehand?(old_table_name)

  Schema.remove_stagehand!(:only => old_table_name)
  super
  Schema.add_stagehand!(:only => new_table_name)
  Staging::CommitEntry.where(:table_name => old_table_name).update_all(:table_name => new_table_name)
end