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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a2a6a3a01c856120842f041db2e36a5193513d4
4
- data.tar.gz: f805ae100d46bd539e53bb2b611cb2a8c520b343
3
+ metadata.gz: ebe04760e55e6d7992dc33a533344a37d1a60bf9
4
+ data.tar.gz: 65d6cc9f67b085aa2dcc2ffc84ace152dbe738a9
5
5
  SHA512:
6
- metadata.gz: 48fc4eeb89f87e4be85eca8da20829ce088b6684094b633d5b2f6751b3a0725ad3edb93db1b0eb7335eeef99993a0f11040cc374fcbd3a31dea98f0426f0cfe8
7
- data.tar.gz: 6688e3bcfa1776c98280f6ac4a33898f99365c50d2763683eb7cf0e36773dc65c5a4088ed6f218a69a1ee542004ee0055dc4e45d87a1c7ee6ec2b50ec1a5affd
6
+ metadata.gz: 8d458df495b75a654cecd2a26f021416ea3034e33a8f36e139862417cdbaae3d023f7c9770f5028237e59e828389547c4bcd13c49bd618cf1050e76a1e1358a9
7
+ data.tar.gz: 8aadc05d246c120cfc960020aa6bbfee8fc8472a435793231227bc3196def7ff526f4fb6841d55407dc9cd6349a3520a75842892029f383c353600497c6d6331
@@ -9,12 +9,12 @@ module Stagehand
9
9
  with_staging_connection(&block)
10
10
  end
11
11
 
12
- def connected_to_production?
13
- current_connection_name == Configuration.production_connection_name
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
- current_connection_name == Configuration.staging_connection_name
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, 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 :not_in_progress, lambda {
28
- joins("LEFT OUTER JOIN (#{ unscoped.select('session, MAX(id) AS start_id').uncontained.start_operations.group('session').to_sql }) AS active_starts
29
- ON active_starts.session = #{table_name}.session AND active_starts.start_id <= #{table_name}.id")
30
- .where("active_starts.start_id IS NULL") }
31
- scope :with_uncontained_keys, lambda {
32
- uncontained
33
- .joins("LEFT OUTER JOIN (#{ unscoped.contained.select('record_id, table_name').distinct.to_sql}) AS contained
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
- .where("contained.record_id IS NULL")
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
- deleted_count += CommitEntry.matching(entry).delete_all
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
 
@@ -1,3 +1,3 @@
1
1
  module Stagehand
2
- VERSION = "0.14.0"
2
+ VERSION = "0.14.1"
3
3
  end
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.0
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-07-19 00:00:00.000000000 Z
12
+ date: 2017-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails