culturecode_stagehand 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 764024a2751221f034e59dd01d47ba537c18231c
|
4
|
+
data.tar.gz: 306cb8e2ab525a4b85c13bcc7cb818572158127d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 310328eb8b60bbadd3a58bfdfae0565b7bb51170d3cc3bb06fa6050962d23efc03a6365f49bf8713b173df2fcf707e9de2fa07b3865357b00d02bbfc00c1d314
|
7
|
+
data.tar.gz: 85b5fb29cae9d1e3d1c81fd847b6caf35b864bd9dca1fcc87f7003446bccc98b605070a31b205333190b2af5e13d10ec867d0948119a3779a16fc28d9ba3f9c5
|
data/lib/stagehand/schema.rb
CHANGED
@@ -20,11 +20,7 @@ module Stagehand
|
|
20
20
|
add_index :stagehand_commit_entries, [:record_id, :table_name] # Used for 'matching' scope
|
21
21
|
add_index :stagehand_commit_entries, [:operation, :commit_id] # Used for looking up start entries, and 'not_in_progress' scope
|
22
22
|
|
23
|
-
|
24
|
-
ActiveRecord::Base.connection.execute("DROP TRIGGER IF EXISTS stagehand_session_trigger;")
|
25
|
-
ActiveRecord::Base.connection.execute("
|
26
|
-
CREATE TRIGGER stagehand_session_trigger BEFORE INSERT ON stagehand_commit_entries
|
27
|
-
FOR EACH ROW SET NEW.session = CONNECTION_ID();")
|
23
|
+
Stagehand::Schema.send :create_session_trigger
|
28
24
|
end
|
29
25
|
|
30
26
|
add_stagehand!(options)
|
@@ -38,9 +34,9 @@ module Stagehand
|
|
38
34
|
table_names &= Array(options[:only]).collect(&:to_s) if options[:only].present?
|
39
35
|
|
40
36
|
table_names.each do |table_name|
|
41
|
-
Stagehand::Schema.send :
|
42
|
-
Stagehand::Schema.send :
|
43
|
-
Stagehand::Schema.send :
|
37
|
+
Stagehand::Schema.send :create_operation_trigger, table_name, 'insert', 'NEW'
|
38
|
+
Stagehand::Schema.send :create_operation_trigger, table_name, 'update', 'NEW'
|
39
|
+
Stagehand::Schema.send :create_operation_trigger, table_name, 'delete', 'OLD'
|
44
40
|
end
|
45
41
|
end
|
46
42
|
end
|
@@ -61,7 +57,9 @@ module Stagehand
|
|
61
57
|
end
|
62
58
|
|
63
59
|
def has_stagehand?(table_name = nil)
|
64
|
-
if table_name
|
60
|
+
if UNTRACKED_TABLES.include?(table_name.to_s)
|
61
|
+
return false
|
62
|
+
elsif table_name
|
65
63
|
trigger_exists?(table_name, 'insert')
|
66
64
|
else
|
67
65
|
ActiveRecord::Base.Connection.table_exists?(Stagehand::Staging::CommitEntry.table_name)
|
@@ -70,29 +68,42 @@ module Stagehand
|
|
70
68
|
|
71
69
|
private
|
72
70
|
|
73
|
-
|
74
|
-
|
71
|
+
# Create trigger to initialize session using a function
|
72
|
+
def create_session_trigger
|
73
|
+
drop_trigger(:stagehand_commit_entries, :insert)
|
74
|
+
create_trigger(:stagehand_commit_entries, :insert, :before, <<-SQL)
|
75
|
+
SET NEW.session = CONNECTION_ID();
|
76
|
+
SQL
|
77
|
+
end
|
78
|
+
|
79
|
+
def create_operation_trigger(table_name, trigger_event, record)
|
80
|
+
return if trigger_exists?(table_name, trigger_event)
|
75
81
|
|
76
|
-
|
77
|
-
CREATE TRIGGER #{trigger_name(table_name, trigger_action)} AFTER #{trigger_action.upcase} ON #{table_name}
|
78
|
-
FOR EACH ROW
|
82
|
+
create_trigger(table_name, trigger_event, :after, <<-SQL)
|
79
83
|
BEGIN
|
80
84
|
INSERT INTO stagehand_commit_entries (record_id, table_name, operation)
|
81
|
-
VALUES (#{record}.id, '#{table_name}', '#{
|
85
|
+
VALUES (#{record}.id, '#{table_name}', '#{trigger_event}');
|
82
86
|
END;
|
83
|
-
|
87
|
+
SQL
|
88
|
+
end
|
89
|
+
|
90
|
+
def create_trigger(table_name, trigger_event, trigger_time, row_action)
|
91
|
+
ActiveRecord::Base.connection.execute <<-SQL
|
92
|
+
CREATE TRIGGER #{trigger_name(table_name, trigger_event)} #{trigger_time} #{trigger_event}
|
93
|
+
ON #{table_name} FOR EACH ROW #{row_action}
|
94
|
+
SQL
|
84
95
|
end
|
85
96
|
|
86
|
-
def drop_trigger(table_name,
|
87
|
-
ActiveRecord::Base.connection.execute("DROP TRIGGER IF EXISTS #{trigger_name(table_name,
|
97
|
+
def drop_trigger(table_name, trigger_event)
|
98
|
+
ActiveRecord::Base.connection.execute("DROP TRIGGER IF EXISTS #{trigger_name(table_name, trigger_event)};")
|
88
99
|
end
|
89
100
|
|
90
|
-
def trigger_exists?(table_name,
|
91
|
-
ActiveRecord::Base.connection.select_one("SHOW TRIGGERS where `trigger` = '#{trigger_name(table_name,
|
101
|
+
def trigger_exists?(table_name, trigger_event)
|
102
|
+
ActiveRecord::Base.connection.select_one("SHOW TRIGGERS where `trigger` = '#{trigger_name(table_name, trigger_event)}'").present?
|
92
103
|
end
|
93
104
|
|
94
|
-
def trigger_name(table_name,
|
95
|
-
"stagehand_#{
|
105
|
+
def trigger_name(table_name, trigger_event)
|
106
|
+
"stagehand_#{trigger_event}_trigger_#{table_name}".downcase
|
96
107
|
end
|
97
108
|
end
|
98
109
|
end
|
@@ -5,9 +5,10 @@ module Stagehand
|
|
5
5
|
def create_table(table_name, options = {})
|
6
6
|
super
|
7
7
|
|
8
|
+
return if Database.connected_to_production? && !Stagehand::Configuration.single_connection?
|
9
|
+
Schema.send(:create_session_trigger) if table_name == Staging::CommitEntry.table_name
|
8
10
|
return if options.symbolize_keys[:stagehand] == false
|
9
11
|
return if UNTRACKED_TABLES.include?(table_name)
|
10
|
-
return if Database.connected_to_production? && !Stagehand::Configuration.single_connection?
|
11
12
|
|
12
13
|
Schema.add_stagehand! :only => table_name
|
13
14
|
end
|
@@ -7,6 +7,7 @@ module Stagehand
|
|
7
7
|
|
8
8
|
def self.capture(subject_record = nil, &block)
|
9
9
|
start_operation = start_commit(subject_record)
|
10
|
+
init_session!(start_operation)
|
10
11
|
block.call(start_operation)
|
11
12
|
return end_commit(start_operation)
|
12
13
|
rescue => e
|
@@ -39,7 +40,7 @@ module Stagehand
|
|
39
40
|
|
40
41
|
start_operation.subject = subject_record
|
41
42
|
|
42
|
-
return start_operation
|
43
|
+
return start_operation
|
43
44
|
end
|
44
45
|
|
45
46
|
# Sets the commit_id on all the entries between the start and end op.
|
@@ -55,6 +56,12 @@ module Stagehand
|
|
55
56
|
return new(start_operation.id)
|
56
57
|
end
|
57
58
|
|
59
|
+
# Reload to ensure session set by the database is read by ActiveRecord
|
60
|
+
def self.init_session!(entry)
|
61
|
+
entry.reload
|
62
|
+
raise BlankCommitEntrySession unless entry.session.present?
|
63
|
+
end
|
64
|
+
|
58
65
|
public
|
59
66
|
|
60
67
|
def initialize(start_id)
|
@@ -100,4 +107,5 @@ module Stagehand
|
|
100
107
|
|
101
108
|
# EXCEPTIONS
|
102
109
|
class CommitNotFound < StandardError; end
|
110
|
+
class BlankCommitEntrySession < StandardError; end
|
103
111
|
end
|
@@ -5,12 +5,12 @@ module Stagehand
|
|
5
5
|
|
6
6
|
class_methods do
|
7
7
|
def connection
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
Stagehand::Database::StagingProbe.connection
|
12
|
-
else
|
8
|
+
if Configuration.ghost_mode?
|
9
|
+
super
|
10
|
+
elsif Stagehand::Database.connected_to_staging?
|
13
11
|
ActiveRecord::Base.connection
|
12
|
+
else
|
13
|
+
Stagehand::Database::StagingProbe.connection
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -9,11 +9,11 @@ module Stagehand
|
|
9
9
|
|
10
10
|
# Immediately attempt to sync the changes from the block if possible
|
11
11
|
# The block is wrapped in a transaction to prevent changes to records while being synced
|
12
|
-
def sync_now(&block)
|
12
|
+
def sync_now(subject_record = nil, &block)
|
13
13
|
raise SyncBlockRequired unless block_given?
|
14
14
|
|
15
15
|
Database.transaction do
|
16
|
-
checklist = Checklist.new(Commit.capture(&block).entries, :preconfirm_subject => false)
|
16
|
+
checklist = Checklist.new(Commit.capture(subject_record, &block).entries, :preconfirm_subject => false)
|
17
17
|
sync_checklist(checklist) unless checklist.requires_confirmation?
|
18
18
|
end
|
19
19
|
end
|
data/lib/stagehand/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: culturecode_stagehand
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicholas Jakobsen
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-09-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|