culturecode_stagehand 0.14.0 → 0.14.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/stagehand/database.rb +4 -4
- data/lib/stagehand/staging/commit_entry.rb +22 -18
- data/lib/stagehand/staging/synchronizer.rb +4 -1
- data/lib/stagehand/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebe04760e55e6d7992dc33a533344a37d1a60bf9
|
4
|
+
data.tar.gz: 65d6cc9f67b085aa2dcc2ffc84ace152dbe738a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d458df495b75a654cecd2a26f021416ea3034e33a8f36e139862417cdbaae3d023f7c9770f5028237e59e828389547c4bcd13c49bd618cf1050e76a1e1358a9
|
7
|
+
data.tar.gz: 8aadc05d246c120cfc960020aa6bbfee8fc8472a435793231227bc3196def7ff526f4fb6841d55407dc9cd6349a3520a75842892029f383c353600497c6d6331
|
data/lib/stagehand/database.rb
CHANGED
@@ -9,12 +9,12 @@ module Stagehand
|
|
9
9
|
with_staging_connection(&block)
|
10
10
|
end
|
11
11
|
|
12
|
-
def connected_to_production?
|
13
|
-
|
12
|
+
def connected_to_production?(klass = ActiveRecord::Base)
|
13
|
+
klass.connection.current_database == production_database_name
|
14
14
|
end
|
15
15
|
|
16
|
-
def connected_to_staging?
|
17
|
-
|
16
|
+
def connected_to_staging?(klass = ActiveRecord::Base)
|
17
|
+
klass.connection.current_database == staging_database_name
|
18
18
|
end
|
19
19
|
|
20
20
|
def production_connection
|
@@ -15,25 +15,29 @@ module Stagehand
|
|
15
15
|
CONTENT_OPERATIONS = [INSERT_OPERATION, UPDATE_OPERATION, DELETE_OPERATION]
|
16
16
|
SAVE_OPERATIONS = [INSERT_OPERATION, UPDATE_OPERATION]
|
17
17
|
|
18
|
-
scope :start_operations,
|
19
|
-
scope :end_operations,
|
20
|
-
scope :control_operations,
|
21
|
-
scope :content_operations,
|
22
|
-
scope :save_operations,
|
23
|
-
scope :delete_operations,
|
24
|
-
scope :with_record,
|
25
|
-
scope :uncontained,
|
26
|
-
scope :contained,
|
27
|
-
scope :
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
18
|
+
scope :start_operations, lambda { where(:operation => START_OPERATION) }
|
19
|
+
scope :end_operations, lambda { where(:operation => END_OPERATION) }
|
20
|
+
scope :control_operations, lambda { where(:operation => CONTROL_OPERATIONS) }
|
21
|
+
scope :content_operations, lambda { where(:operation => CONTENT_OPERATIONS) }
|
22
|
+
scope :save_operations, lambda { where(:operation => SAVE_OPERATIONS) }
|
23
|
+
scope :delete_operations, lambda { where(:operation => DELETE_OPERATION) }
|
24
|
+
scope :with_record, lambda { where.not(:record_id => nil) }
|
25
|
+
scope :uncontained, lambda { where(:commit_id => nil) }
|
26
|
+
scope :contained, lambda { where.not(:commit_id => nil) }
|
27
|
+
scope :no_newer_than, lambda {|entry| where("id <= ?", entry) }
|
28
|
+
scope :in_progress, lambda { joins_active_commits }
|
29
|
+
scope :not_in_progress, lambda { joins_active_commits("LEFT OUTER").where("active_commits.commit_id IS NULL") }
|
30
|
+
scope :with_uncontained_keys, lambda { uncontained.joins_contained("LEFT OUTER").where("contained.record_id IS NULL") }
|
31
|
+
|
32
|
+
def self.joins_active_commits(type = "INNER")
|
33
|
+
joins("#{type} JOIN (#{ unscoped.select('session, MAX(id) AS commit_id').uncontained.start_operations.group('session').to_sql }) AS active_commits
|
34
|
+
ON active_commits.session = #{table_name}.session AND active_commits.commit_id <= #{table_name}.id")
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.joins_contained(type = "INNER")
|
38
|
+
joins("#{type} JOIN (#{ unscoped.contained.select('record_id, table_name').distinct.to_sql}) AS contained
|
34
39
|
ON contained.record_id = #{table_name}.record_id AND contained.table_name = #{table_name}.table_name")
|
35
|
-
|
36
|
-
}
|
40
|
+
end
|
37
41
|
|
38
42
|
def self.matching(object)
|
39
43
|
keys = Array.wrap(object).collect {|entry| Stagehand::Key.generate(entry) }.compact
|
@@ -30,12 +30,15 @@ module Stagehand
|
|
30
30
|
def sync(limit = nil)
|
31
31
|
synced_count = 0
|
32
32
|
deleted_count = 0
|
33
|
+
in_progress = nil
|
33
34
|
|
34
35
|
Rails.logger.info "Syncing"
|
36
|
+
|
35
37
|
iterate_autosyncable_entries do |entry|
|
36
38
|
sync_entry(entry, :callbacks => :sync)
|
37
39
|
synced_count += 1
|
38
|
-
|
40
|
+
in_progress ||= CommitEntry.in_progress.pluck(:id)
|
41
|
+
deleted_count += CommitEntry.matching(entry).no_newer_than(entry).where.not(:id => in_progress).delete_all
|
39
42
|
break if synced_count == limit
|
40
43
|
end
|
41
44
|
|
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.14.
|
4
|
+
version: 0.14.1
|
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: 2017-
|
12
|
+
date: 2017-09-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|