usps-support 0.2.30 → 0.2.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6dd7254a5f59aa252cd188286d4b1bbdb365b7897a4501ccd1d2af6e7d4674b7
|
|
4
|
+
data.tar.gz: 822c2f45772cd5917917d1371582d5c7740946ff192893d26165e36e54da8b12
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0d7bee79730a699e6f24da6f38bec176bcfc61855959e0c011b79689313f66cf158b4b701dfd7c97f187fca3bd7aaf7fab9fb6cc1f4259d1a3883ec0a0068feb
|
|
7
|
+
data.tar.gz: 629ceef5d2ac5dc7d4898a094360e51d4d35860dd1cd9e5538bf30fef5be852db907684b34ebe33a7cde6408bc31d0348be0bfa5878f578e1d85b3879806f975
|
data/lib/tasks/db.rake
CHANGED
|
@@ -1,34 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'usps/support/db/auxiliary_stamper'
|
|
4
|
+
|
|
3
5
|
namespace :db do
|
|
4
6
|
desc "Stamp auxiliary test databases with the primary database's schema_migrations rows"
|
|
5
7
|
task stamp_auxiliary_test_schemas: :environment do
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
configs = ActiveRecord::Base.configurations.configs_for(env_name: 'test')
|
|
9
|
-
primary = configs.find(&:primary?) || configs.first
|
|
10
|
-
auxiliary = configs - [primary]
|
|
11
|
-
next if auxiliary.empty?
|
|
12
|
-
|
|
13
|
-
connection = ActiveRecord::Base.connection
|
|
14
|
-
primary_versions =
|
|
15
|
-
connection
|
|
16
|
-
.execute("SELECT version FROM #{primary.database}.schema_migrations")
|
|
17
|
-
.to_a.flatten
|
|
18
|
-
|
|
19
|
-
auxiliary.each do |config|
|
|
20
|
-
existing =
|
|
21
|
-
connection
|
|
22
|
-
.execute("SELECT version FROM #{config.database}.schema_migrations")
|
|
23
|
-
.to_a.flatten
|
|
24
|
-
|
|
25
|
-
(primary_versions - existing).each do |version|
|
|
26
|
-
puts "Stamping #{version} for #{config.database}"
|
|
27
|
-
connection.execute(
|
|
28
|
-
"INSERT INTO #{config.database}.schema_migrations (version) VALUES (#{version.to_i})"
|
|
29
|
-
)
|
|
30
|
-
end
|
|
31
|
-
end
|
|
8
|
+
Usps::Support::Db::AuxiliaryStamper.call
|
|
32
9
|
end
|
|
33
10
|
end
|
|
34
11
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Usps
|
|
4
|
+
module Support
|
|
5
|
+
module Db
|
|
6
|
+
# Copies the primary test database's schema_migrations rows into each
|
|
7
|
+
# auxiliary test database, so Rails' pending-migration check doesn't see
|
|
8
|
+
# the primary's migrations as pending against schemas that don't run them.
|
|
9
|
+
#
|
|
10
|
+
module AuxiliaryStamper
|
|
11
|
+
class << self
|
|
12
|
+
def call(io: $stdout)
|
|
13
|
+
primary, auxiliary = test_configs
|
|
14
|
+
return if auxiliary.empty?
|
|
15
|
+
|
|
16
|
+
ActiveRecord::Base.connection_pool.with_connection do |connection|
|
|
17
|
+
primary_versions = fetch_versions(connection, primary.database)
|
|
18
|
+
|
|
19
|
+
auxiliary.each do |config|
|
|
20
|
+
existing = fetch_versions(connection, config.database)
|
|
21
|
+
(primary_versions - existing).each do |version|
|
|
22
|
+
io.puts "Stamping #{version} for #{config.database}"
|
|
23
|
+
connection.execute(
|
|
24
|
+
"INSERT INTO #{config.database}.schema_migrations (version) VALUES (#{version.to_i})"
|
|
25
|
+
)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def test_configs
|
|
34
|
+
configs = ActiveRecord::Base.configurations.configs_for(env_name: 'test')
|
|
35
|
+
primary = configs.find(&:primary?) || configs.first
|
|
36
|
+
[primary, configs - [primary]]
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def fetch_versions(connection, database)
|
|
40
|
+
connection.execute("SELECT version FROM #{database}.schema_migrations").to_a.flatten
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
data/lib/usps/support/railtie.rb
CHANGED
|
@@ -4,7 +4,9 @@ require 'rails'
|
|
|
4
4
|
|
|
5
5
|
module Usps
|
|
6
6
|
module Support
|
|
7
|
-
# Expose rake tasks to Rails
|
|
7
|
+
# Expose rake tasks to Rails and ensure auxiliary test schemas stay in
|
|
8
|
+
# sync with the primary's schema_migrations before Rails runs its
|
|
9
|
+
# pending-migration check.
|
|
8
10
|
#
|
|
9
11
|
class Railtie < Rails::Railtie
|
|
10
12
|
railtie_name :usps_support
|
|
@@ -13,6 +15,23 @@ module Usps
|
|
|
13
15
|
path = File.expand_path(__dir__)
|
|
14
16
|
Dir.glob("#{path}/../../tasks/**/*.rake").each { |f| load f }
|
|
15
17
|
end
|
|
18
|
+
|
|
19
|
+
initializer 'usps_support.stamp_auxiliary_test_schemas' do
|
|
20
|
+
next unless Rails.env.test?
|
|
21
|
+
|
|
22
|
+
require 'usps/support/db/auxiliary_stamper'
|
|
23
|
+
|
|
24
|
+
ActiveSupport.on_load(:active_record) do
|
|
25
|
+
ActiveRecord::Migration.singleton_class.prepend(
|
|
26
|
+
Module.new do
|
|
27
|
+
def maintain_test_schema!
|
|
28
|
+
Usps::Support::Db::AuxiliaryStamper.call(io: File.open(File::NULL, 'w'))
|
|
29
|
+
super
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
16
35
|
end
|
|
17
36
|
end
|
|
18
37
|
end
|
data/lib/usps/support/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: usps-support
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.32
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Julian Fiander
|
|
@@ -68,6 +68,7 @@ files:
|
|
|
68
68
|
- lib/tasks/db.rake
|
|
69
69
|
- lib/usps/all.rb
|
|
70
70
|
- lib/usps/support.rb
|
|
71
|
+
- lib/usps/support/db/auxiliary_stamper.rb
|
|
71
72
|
- lib/usps/support/db/members_schema.rb
|
|
72
73
|
- lib/usps/support/db/websites_schema.rb
|
|
73
74
|
- lib/usps/support/engine.rb
|