usps-support 0.2.31 → 0.2.33

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: 11a06c8340516331eb50d88f716946ceb8eb83f05c12743bd2f4e22931fd12f9
4
- data.tar.gz: 9a3f75af59599515b8bea10866ecdcd1b347efc888b92a1ad547f8a11fbff844
3
+ metadata.gz: 0fbc6292bf62cc060ed4e6a98f6b1401a4272c933e62122c4082270548714626
4
+ data.tar.gz: 45ea123c687a9e4f7bd3061363a462f708be5f5afb9ffd2f86151a34c6d660fd
5
5
  SHA512:
6
- metadata.gz: ac4a3f5647926dbfce0e451ee2cd88d9984b6fa585e6c7ceed4537ff1cdc158a71a03259d7aef9abfd043738016b2f4eee57108441acdb1d686b12ad3cbc2097
7
- data.tar.gz: 4e60a2fa35eb2c30f7df75c933097ca69a0b1c062ce2f0a9a1e9353934c5ad8a904ba5f5f01ebb14002a70a5900fec65f709332f48109b5e1fa856544a00a21a
6
+ metadata.gz: 707d6521fd4f39da121ed4f8e1b5a64c4184519f2e4843c682df242a8a01e3992cc15e6ecaac36acde4cb8cfea81e54df7d02667ca0901457568c228135254e4
7
+ data.tar.gz: 75f986edbfc945c91b5c54e5aa3cd55f994976cb60bc20731e79822506d92e460255ff791826d7024a9f3ed0901f09b2fd03ee2302c26254aebece3e2d016927
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
- next unless Rails.env.test?
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
@@ -20,6 +20,10 @@ module Usps::Support::Models
20
20
  client.commit("#{ORG}/#{repo}", sha).commit
21
21
  end
22
22
 
23
+ def repository_workflow_runs(repo, head_sha:)
24
+ client.repository_workflow_runs("#{ORG}/#{repo}", head_sha:).workflow_runs
25
+ end
26
+
23
27
  def latest_tag(repo, include_prereleases: false)
24
28
  client
25
29
  .tags("#{ORG}/#{repo}")
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module Support
5
- VERSION = '0.2.31'
5
+ VERSION = '0.2.33'
6
6
  end
7
7
  end
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.31
4
+ version: 0.2.33
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