storey 2.1.0 → 2.1.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
  SHA256:
3
- metadata.gz: 4d868102f5a1ce14a7d937639ab4cda6b59ed9d10be52bee5ce219d46cadddfc
4
- data.tar.gz: b6d1ae7e3276463d5fed292024f5d2ea19be909d5fa9075bc4e731a5d1127fda
3
+ metadata.gz: 077fb1249a3bf984d1613b1351468cebf881bde2ac2e4f299d3b9d17a877d0e5
4
+ data.tar.gz: 38f7315acb1dcb9c3545a64dca60e67105d6b8520cd276ae1dec8997b4028ec7
5
5
  SHA512:
6
- metadata.gz: 9838fa46e3d3c84c17e2994587759db404ca47e6bbb1dc666bf76cc9c79348d6fad7dc677cfd5967af376d385e4eb3532eed4f2eb7d50a078788dcc3eb87a82b
7
- data.tar.gz: 8d45a6ad1b0cac2f3a3b708b070684b7ff3134b8b41a7e38fbc8b4c135f27f91ab45bb363d48dfc4cc9b5723e9b18574f794ce7c6ed546dde20279bc81f5d4a7
6
+ metadata.gz: 3d5cc746a06923f49fe9226c8183aaf9a68293a6639a24108fc3b161ab15bf78342bf7124ffa1ac9ded5f4055b75d01be1f815cb67cae65013b6ce12d41b32e6
7
+ data.tar.gz: 1418cbe848c0e891c5e7c70f05ac5384b79946b9cc878b1e92e918032fbfa36cef8a5209fe89c0a3dcbcea19262cd0a4aea9fcec9e5a3d60d156e2ba36401784
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
+ ## [2.1.1] - 2018-07-04
6
+ ### Fixed
7
+ - Fix copying of schemas in when ActiveRecord caches queries
8
+
5
9
  ## [2.1.0] - 2018-07-04
6
10
  ### Added
7
11
  - Print duplication stdout for debugging
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- storey (2.1.0)
4
+ storey (2.1.1)
5
5
  easy_class_to_instance_method (~> 0.0.2)
6
6
  gem_config
7
7
  pg
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- storey (2.1.0)
4
+ storey (2.1.1)
5
5
  easy_class_to_instance_method (~> 0.0.2)
6
6
  gem_config
7
7
  pg
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- storey (2.1.0)
4
+ storey (2.1.1)
5
5
  easy_class_to_instance_method (~> 0.0.2)
6
6
  gem_config
7
7
  pg
@@ -96,20 +96,18 @@ module Storey
96
96
  def copy_source_schema_migrations
97
97
  ::Storey.switch @target_schema do
98
98
  source_schema_migrations.each do |version|
99
- unless target_schema_migrations.include?(version)
100
- command = "INSERT INTO schema_migrations (version) VALUES ('#{version}');"
101
- ::ActiveRecord::Base.connection.execute command
102
- end
99
+ ActiveRecord::SchemaMigration.where(version: version).
100
+ first_or_create!
103
101
  end
104
102
  end
105
103
  end
106
104
 
107
105
  def source_schema_migrations
108
- GetMigrationVersions.(@source_schema)
106
+ @source_schema_migrations ||= GetMigrationVersions.(@source_schema)
109
107
  end
110
108
 
111
109
  def target_schema_migrations
112
- GetMigrationVersions.(@target_schema)
110
+ @target_schema_migrations ||= GetMigrationVersions.(@target_schema)
113
111
  end
114
112
 
115
113
  def replace_occurrences
@@ -9,11 +9,13 @@ module Storey
9
9
  private
10
10
 
11
11
  def self.migration_versions
12
- if Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new("5.2")
13
- ::ActiveRecord::Migrator.get_all_versions
14
- else
15
- ::ActiveRecord::Base.connection.migration_context.
16
- get_all_versions
12
+ ActiveRecord::Base.connection.uncached do
13
+ if Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new("5.2")
14
+ ::ActiveRecord::Migrator.get_all_versions
15
+ else
16
+ ::ActiveRecord::Base.connection.migration_context.
17
+ get_all_versions
18
+ end
17
19
  end
18
20
  end
19
21
 
@@ -1,3 +1,3 @@
1
1
  module Storey
2
- VERSION = "2.1.0"
2
+ VERSION = "2.1.1"
3
3
  end
@@ -13,4 +13,19 @@ RSpec.describe Storey do
13
13
  end
14
14
  end
15
15
 
16
+ describe ".switch" do
17
+ it "does not cache between switches" do
18
+ Storey.create("s1") do
19
+ 2.times {|n| Post.create(name: n.to_s) }
20
+ end
21
+
22
+ Storey.create("s2") do
23
+ 3.times {|n| Post.create(name: n.to_s) }
24
+ end
25
+
26
+ Storey.switch("s1") { expect(Post.count).to eq 2 }
27
+ Storey.switch("s2") { expect(Post.count).to eq 3 }
28
+ end
29
+ end
30
+
16
31
  end
data/spec/spec_helper.rb CHANGED
@@ -14,6 +14,12 @@ require 'pry'
14
14
  RSpec.configure do |config|
15
15
  config.order = 'random'
16
16
 
17
+ config.before(:suite) do
18
+ # Enable query cache so we can catch unexpected behaviour with AR
19
+ # caching
20
+ ActiveRecord::Base.connection.enable_query_cache!
21
+ end
22
+
17
23
  config.before(:each) do
18
24
  # We don't want configuration to leak into other tests
19
25
  Storey.reload_config!
@@ -27,6 +27,20 @@ describe Storey::Duplicator do
27
27
  expect(Dir[source_dump_dir]).to be_empty
28
28
  expect(Dir[target_dump_dir]).to be_empty
29
29
  end
30
+
31
+ it "does not used cached schema migration versions when copying" do
32
+ s1_versions_count = nil
33
+ Storey.create("s1") do
34
+ s1_versions_count = ActiveRecord::SchemaMigration.count
35
+ end
36
+
37
+ duplicator = described_class.new('s1', 's2')
38
+ duplicator.perform!
39
+
40
+ Storey.switch("s2") do
41
+ expect(ActiveRecord::SchemaMigration.count).to eq s1_versions_count
42
+ end
43
+ end
30
44
  end
31
45
 
32
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: storey
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ramon Tayag