Module: Stagehand::Schema
- Extended by:
- Schema
- Included in:
- Schema
- Defined in:
- lib/stagehand/schema.rb,
lib/stagehand/schema/statements.rb
Defined Under Namespace
Modules: DumperExtensions, Statements
Constant Summary
collapse
- UNTRACKED_TABLES =
['schema_migrations', Stagehand::Staging::CommitEntry.table_name]
Instance Method Summary
collapse
Instance Method Details
#add_stagehand!(options = {}) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/stagehand/schema.rb', line 30
def add_stagehand!(options = {})
ActiveRecord::Schema.define do
table_names = ActiveRecord::Base.connection.tables
table_names -= UNTRACKED_TABLES
table_names -= Array(options[:except]).collect(&:to_s)
table_names &= Array(options[:only]).collect(&:to_s) if options[:only].present?
table_names.each do |table_name|
Stagehand::Schema.send :create_operation_trigger, table_name, 'insert', 'NEW'
Stagehand::Schema.send :create_operation_trigger, table_name, 'update', 'NEW'
Stagehand::Schema.send :create_operation_trigger, table_name, 'delete', 'OLD'
end
end
end
|
#has_stagehand?(table_name = nil) ⇒ Boolean
60
61
62
63
64
65
66
67
68
|
# File 'lib/stagehand/schema.rb', line 60
def has_stagehand?(table_name = nil)
if UNTRACKED_TABLES.include?(table_name.to_s)
return false
elsif table_name
trigger_exists?(table_name, 'insert')
else
ActiveRecord::Base.Connection.table_exists?(Stagehand::Staging::CommitEntry.table_name)
end
end
|
#init_stagehand!(options = {}) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/stagehand/schema.rb', line 9
def init_stagehand!(options = {})
ActiveRecord::Schema.define do
create_table :stagehand_commit_entries do |t|
t.integer :record_id
t.string :table_name
t.string :operation, :null => false
t.integer :commit_id
t.string :session
t.datetime :created_at
end
add_index :stagehand_commit_entries, :commit_id add_index :stagehand_commit_entries, [:record_id, :table_name] add_index :stagehand_commit_entries, [:operation, :commit_id]
Stagehand::Schema.send :create_session_trigger
end
add_stagehand!(options)
end
|
#remove_stagehand!(options = {}) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/stagehand/schema.rb', line 45
def remove_stagehand!(options = {})
ActiveRecord::Schema.define do
table_names = ActiveRecord::Base.connection.tables
table_names &= Array(options[:only]).collect(&:to_s) if options[:only].present?
table_names.each do |table_name|
Stagehand::Schema.send :drop_trigger, table_name, 'insert'
Stagehand::Schema.send :drop_trigger, table_name, 'update'
Stagehand::Schema.send :drop_trigger, table_name, 'delete'
end
drop_table :stagehand_commit_entries unless options[:only].present?
end
end
|