activerecord-safer_migrations 2.0.0 → 4.0.0

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
- SHA1:
3
- metadata.gz: 22edc1b74891b126918870a164f1213a79e92627
4
- data.tar.gz: 153a817bf13c44c28a22ba7048756e4d61dcaf43
2
+ SHA256:
3
+ metadata.gz: eea049e010a0e70538da15050fc12dc357e3a2a4bd7a282cabd50d0662b73abc
4
+ data.tar.gz: b10bff633844c10c31604a9acb6019942e767da89a389c0a03e01df48bc80001
5
5
  SHA512:
6
- metadata.gz: 5cd1cfa6177e67981bf0060740d899504ab15945f59e48627b7053450483fd50bd7bbeaac137ef1410ac30b5c35a07b6d86935114b469d7902519875711c9e78
7
- data.tar.gz: 75866edc3cfb0eac725953860a47f80f72212803b5f40f49cd62cc474720da6b13e83b882dfccc78f5b6b3e88369126a36a460ea45b080bb65a1b95cca4b9157
6
+ metadata.gz: 86e5460e1a23eae1b87c34b0df46802315ac0dd0d092de4e2e9b5802af8c656b266e983f1b8ef9d5fe72957467b6ab0742ab95a168c97d7f7b5c1dfd213bde31
7
+ data.tar.gz: 0d79dcfd2741bd38e2e4048c4da1839ae7f0f991bc5f089695eb886eb8dbe8010ba520accfea9499b18af0dcdb5cd61671fdd79b91f3b11601fb85393e1a9cc5
@@ -0,0 +1,7 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ open-pull-requests-limit: 10
@@ -0,0 +1,60 @@
1
+ name: tests
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - "master"
7
+ pull_request:
8
+
9
+ concurrency:
10
+ group: ${{ github.workflow }}-${{ github.ref }}
11
+ cancel-in-progress: true
12
+
13
+ jobs:
14
+ rubocop:
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ - uses: ruby/setup-ruby@v1
19
+ with:
20
+ bundler-cache: true
21
+ - run: bundle exec rubocop --extra-details --display-style-guide --parallel --force-exclusion
22
+
23
+ tests:
24
+ strategy:
25
+ fail-fast: false
26
+ matrix:
27
+ ruby-version: ["3.1", "3.2", "3.3"]
28
+ activerecord-version:
29
+ - "7.0.8"
30
+ - "7.1.3.4"
31
+ - "7.2.0"
32
+ runs-on: ubuntu-latest
33
+ services:
34
+ postgres:
35
+ image: postgres:14
36
+ env:
37
+ POSTGRES_USER: postgres
38
+ POSTGRES_DB: safer_migrations_test
39
+ POSTGRES_PASSWORD: safer_migrations
40
+ ports:
41
+ - 5432:5432
42
+ options: >-
43
+ --health-cmd pg_isready
44
+ --health-interval 10s
45
+ --health-timeout 5s
46
+ --health-retries 10
47
+ env:
48
+ DATABASE_URL: postgres://postgres:safer_migrations@localhost/safer_migrations_test
49
+ DATABASE_DEPENDENCY_PORT: "5432"
50
+ ACTIVERECORD_VERSION: "${{ matrix.activerecord-version }}"
51
+ steps:
52
+ - uses: actions/checkout@v4
53
+ - name: Set up Ruby
54
+ uses: ruby/setup-ruby@v1
55
+ with:
56
+ bundler-cache: true
57
+ ruby-version: "${{ matrix.ruby-version }}"
58
+ - name: Run specs
59
+ run: |
60
+ bundle exec rspec --profile --format progress
data/.rubocop.yml CHANGED
@@ -1,30 +1,17 @@
1
- AllCops:
2
- DisplayCopNames: true
3
-
4
- # Use trailing rather than leading dots on multi-line call chains
5
- Style/DotPosition:
6
- EnforcedStyle: trailing
7
-
8
- Style/Documentation:
9
- Enabled: false
10
-
11
- Style/StringLiterals:
12
- EnforcedStyle: double_quotes
1
+ inherit_gem:
2
+ gc_ruboconfig: rubocop.yml
13
3
 
14
- Style/TrailingComma:
15
- EnforcedStyleForMultiline: comma
4
+ AllCops:
5
+ TargetRubyVersion: 3.2
6
+ NewCops: enable
16
7
 
17
- Style/AccessorMethodName:
8
+ Gemspec/RequiredRubyVersion:
18
9
  Enabled: false
19
10
 
20
- Style/SignalException:
21
- EnforcedStyle: only_raise
11
+ Naming/FileName:
12
+ Exclude:
13
+ - lib/activerecord-safer_migrations.rb
22
14
 
23
15
  Style/GlobalVars:
24
- Enabled: false
25
-
26
- Style/FileName:
27
- Enabled: false
28
-
29
- Metrics/LineLength:
30
- Max: 100
16
+ Exclude:
17
+ - "spec/active_record/safer_migrations/migration_spec.rb"
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.4.1
1
+ 3.3.4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # 4.0.0 / 2024-08-21
2
+
3
+ - Remove support for Ruby =< 3.0 and Rails < 7.0
4
+ - Add support for ActiveRecord 7.2 (#98)
5
+
6
+ # 3.0.0 / 2020-09-28
7
+
8
+ - [#55](https://github.com/gocardless/activerecord-safer_migrations/pull/55) Drop support for Ruby =< 2.4 and Rails =< 5.1
9
+
1
10
  # 2.0.0 / 2017-08-23
2
11
 
3
12
  - [#23](https://github.com/gocardless/activerecord-safer_migrations/pull/23) Drop support for Rails 4.0 and 4.1
data/Gemfile CHANGED
@@ -1,5 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
5
  gemspec
4
6
 
5
7
  gem "activerecord", "~> #{ENV['ACTIVERECORD_VERSION']}" if ENV["ACTIVERECORD_VERSION"]
8
+
9
+ group :test, :development do
10
+ gem "gc_ruboconfig", "~> 5.0"
11
+ gem "pg", "~> 1.4"
12
+ gem "rspec", "~> 3.13.0"
13
+ end
@@ -1,4 +1,6 @@
1
- require File.expand_path("../lib/active_record/safer_migrations/version", __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path("lib/active_record/safer_migrations/version", __dir__)
2
4
 
3
5
  Gem::Specification.new do |gem|
4
6
  gem.name = "activerecord-safer_migrations"
@@ -12,11 +14,8 @@ Gem::Specification.new do |gem|
12
14
  gem.homepage = "https://github.com/gocardless/activerecord-safer_migrations"
13
15
  gem.license = "MIT"
14
16
 
15
- gem.required_ruby_version = "~> 2.2"
16
-
17
- gem.add_runtime_dependency "activerecord", ">= 4.0"
17
+ gem.required_ruby_version = ">= 3.1"
18
18
 
19
- gem.add_development_dependency "pg", "~> 0.21.0"
20
- gem.add_development_dependency "rspec", "~> 3.3.0"
21
- gem.add_development_dependency "rubocop", "~> 0.35.1"
19
+ gem.add_dependency "activerecord", ">= 7.0"
20
+ gem.metadata["rubygems_mfa_required"] = "true"
22
21
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_record/safer_migrations/setting_helper"
2
4
 
3
5
  module ActiveRecord
@@ -19,9 +21,12 @@ module ActiveRecord
19
21
  def exec_migration(conn, direction)
20
22
  # lock_timeout is an instance accessor created by class_attribute
21
23
  lock_timeout_ms = lock_timeout || SaferMigrations.default_lock_timeout
22
- statement_timeout_ms = statement_timeout || SaferMigrations.default_statement_timeout
24
+ statement_timeout_ms = statement_timeout || SaferMigrations.
25
+ default_statement_timeout
23
26
  SettingHelper.new(conn, :lock_timeout, lock_timeout_ms).with_setting do
24
- SettingHelper.new(conn, :statement_timeout, statement_timeout_ms).with_setting do
27
+ SettingHelper.new(conn,
28
+ :statement_timeout,
29
+ statement_timeout_ms).with_setting do
25
30
  super(conn, direction)
26
31
  end
27
32
  end
@@ -29,8 +34,10 @@ module ActiveRecord
29
34
  end
30
35
 
31
36
  module ClassMethods
37
+ # rubocop:disable Naming/AccessorMethodName
32
38
  def set_lock_timeout(timeout)
33
- if timeout == 0
39
+ # rubocop:enable Naming/AccessorMethodName
40
+ if timeout.zero?
34
41
  raise "Setting lock_timeout to 0 is dangerous - it disables the lock " \
35
42
  "timeout rather than instantly timing out. If you *actually* " \
36
43
  "want to disable the lock timeout (not recommended!), use the " \
@@ -44,12 +51,14 @@ module ActiveRecord
44
51
  self.lock_timeout = 0
45
52
  end
46
53
 
54
+ # rubocop:disable Naming/AccessorMethodName
47
55
  def set_statement_timeout(timeout)
48
- if timeout == 0
49
- raise "Setting statement_timeout to 0 is dangerous - it disables the statement " \
50
- "timeout rather than instantly timing out. If you *actually* " \
51
- "want to disable the statement timeout (not recommended!), use the " \
52
- "`disable_statement_timeout!` method."
56
+ # rubocop:enable Naming/AccessorMethodName
57
+ if timeout.zero?
58
+ raise "Setting statement_timeout to 0 is dangerous - it disables the " \
59
+ "statement timeout rather than instantly timing out. If you " \
60
+ "*actually* want to disable the statement timeout (not recommended!)" \
61
+ ", use the `disable_statement_timeout!` method."
53
62
  end
54
63
  self.statement_timeout = timeout
55
64
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord
2
4
  module SaferMigrations
3
5
  module PostgreSQLAdapter
@@ -31,7 +33,11 @@ module ActiveRecord
31
33
  end
32
34
 
33
35
  def fill_sql_values(sql, values)
34
- ActiveRecord::Base.send(:replace_named_bind_variables, sql, values)
36
+ if ActiveRecord.version >= "7.2.0"
37
+ ActiveRecord::Base.send(:replace_named_bind_variables, self, sql, values)
38
+ else
39
+ ActiveRecord::Base.send(:replace_named_bind_variables, sql, values)
40
+ end
35
41
  end
36
42
  end
37
43
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord
2
4
  module SaferMigrations
3
5
  class Railtie < Rails::Railtie
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord
2
4
  module SaferMigrations
3
5
  class SettingHelper
@@ -20,7 +22,7 @@ module ActiveRecord
20
22
  set_new_setting
21
23
  yield
22
24
  reset_setting
23
- rescue
25
+ rescue StandardError
24
26
  reset_setting unless in_transaction?
25
27
  raise
26
28
  end
@@ -42,7 +44,7 @@ module ActiveRecord
42
44
  end
43
45
 
44
46
  def in_transaction?
45
- ActiveRecord::Base.connection.open_transactions > 0
47
+ ActiveRecord::Base.connection.open_transactions.positive?
46
48
  end
47
49
  end
48
50
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord
2
4
  module SaferMigrations
3
- VERSION = "2.0.0".freeze
5
+ VERSION = "4.0.0"
4
6
  end
5
7
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_record/connection_adapters/postgresql_adapter"
2
4
  require "active_record/safer_migrations/postgresql_adapter"
3
5
  require "active_record/safer_migrations/migration"
@@ -35,4 +37,4 @@ module ActiveRecord
35
37
  end
36
38
  end
37
39
 
38
- require "active_record/safer_migrations/railtie" if defined?(::Rails)
40
+ require "active_record/safer_migrations/railtie" if defined?(Rails)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  RSpec.describe ActiveRecord::SaferMigrations::Migration do
@@ -9,13 +11,17 @@ RSpec.describe ActiveRecord::SaferMigrations::Migration do
9
11
  end
10
12
  end
11
13
 
12
- before { nuke_migrations }
13
- before { TimeoutTestHelpers.set(:lock_timeout, 0) }
14
- before { TimeoutTestHelpers.set(:statement_timeout, 0) }
14
+ before do
15
+ nuke_migrations
16
+ TimeoutTestHelpers.set(:lock_timeout, 0)
17
+ TimeoutTestHelpers.set(:statement_timeout, 0)
18
+ end
15
19
 
16
20
  describe "setting timeouts explicitly" do
17
- before { $lock_timeout = nil }
18
- before { $statement_timeout = nil }
21
+ before do
22
+ $lock_timeout = nil
23
+ $statement_timeout = nil
24
+ end
19
25
 
20
26
  shared_examples_for "running the migration" do
21
27
  let(:migration) do
@@ -51,8 +57,10 @@ RSpec.describe ActiveRecord::SaferMigrations::Migration do
51
57
  end
52
58
 
53
59
  context "when the original timeout is not 0" do
54
- before { TimeoutTestHelpers.set(:lock_timeout, 8000) }
55
- before { TimeoutTestHelpers.set(:statement_timeout, 8001) }
60
+ before do
61
+ TimeoutTestHelpers.set(:lock_timeout, 8000)
62
+ TimeoutTestHelpers.set(:statement_timeout, 8001)
63
+ end
56
64
 
57
65
  it "unsets the lock timeout after the migration" do
58
66
  silence_stream($stdout) { run_migration.call }
@@ -82,10 +90,13 @@ RSpec.describe ActiveRecord::SaferMigrations::Migration do
82
90
  end
83
91
 
84
92
  describe "the default timeouts" do
85
- before { $lock_timeout = nil }
86
- before { $statement_timeout = nil }
87
- before { ActiveRecord::SaferMigrations.default_lock_timeout = 6000 }
88
- before { ActiveRecord::SaferMigrations.default_statement_timeout = 6001 }
93
+ before do
94
+ $lock_timeout = nil
95
+ $statement_timeout = nil
96
+ ActiveRecord::SaferMigrations.default_lock_timeout = 6000
97
+ ActiveRecord::SaferMigrations.default_statement_timeout = 6001
98
+ end
99
+
89
100
  let(:migration) do
90
101
  Class.new(migration_base_class) do
91
102
  def change
@@ -117,10 +128,13 @@ RSpec.describe ActiveRecord::SaferMigrations::Migration do
117
128
  end
118
129
 
119
130
  describe "when inheriting from a migration with timeouts defined" do
120
- before { $lock_timeout = nil }
121
- before { $statement_timeout = nil }
122
- before { ActiveRecord::SaferMigrations.default_lock_timeout = 6000 }
123
- before { ActiveRecord::SaferMigrations.default_statement_timeout = 6001 }
131
+ before do
132
+ $lock_timeout = nil
133
+ $statement_timeout = nil
134
+ ActiveRecord::SaferMigrations.default_lock_timeout = 6000
135
+ ActiveRecord::SaferMigrations.default_statement_timeout = 6001
136
+ end
137
+
124
138
  let(:base_migration) do
125
139
  Class.new(migration_base_class) do
126
140
  set_lock_timeout(7000)
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_record"
2
4
  require "activerecord-safer_migrations"
3
5
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-safer_migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GoCardless Engineering
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-23 00:00:00.000000000 Z
11
+ date: 2024-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,66 +16,25 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: '7.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.0'
27
- - !ruby/object:Gem::Dependency
28
- name: pg
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: 0.21.0
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: 0.21.0
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 3.3.0
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 3.3.0
55
- - !ruby/object:Gem::Dependency
56
- name: rubocop
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: 0.35.1
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: 0.35.1
26
+ version: '7.0'
69
27
  description: ''
70
28
  email: developers@gocardless.com
71
29
  executables: []
72
30
  extensions: []
73
31
  extra_rdoc_files: []
74
32
  files:
33
+ - ".github/dependabot.yml"
34
+ - ".github/workflows/tests.yml"
75
35
  - ".gitignore"
76
36
  - ".rubocop.yml"
77
37
  - ".ruby-version"
78
- - ".travis.yml"
79
38
  - CHANGELOG.md
80
39
  - Gemfile
81
40
  - LICENSE.txt
@@ -92,25 +51,25 @@ files:
92
51
  homepage: https://github.com/gocardless/activerecord-safer_migrations
93
52
  licenses:
94
53
  - MIT
95
- metadata: {}
96
- post_install_message:
54
+ metadata:
55
+ rubygems_mfa_required: 'true'
56
+ post_install_message:
97
57
  rdoc_options: []
98
58
  require_paths:
99
59
  - lib
100
60
  required_ruby_version: !ruby/object:Gem::Requirement
101
61
  requirements:
102
- - - "~>"
62
+ - - ">="
103
63
  - !ruby/object:Gem::Version
104
- version: '2.2'
64
+ version: '3.1'
105
65
  required_rubygems_version: !ruby/object:Gem::Requirement
106
66
  requirements:
107
67
  - - ">="
108
68
  - !ruby/object:Gem::Version
109
69
  version: '0'
110
70
  requirements: []
111
- rubyforge_project:
112
- rubygems_version: 2.6.11
113
- signing_key:
71
+ rubygems_version: 3.5.11
72
+ signing_key:
114
73
  specification_version: 4
115
74
  summary: ActiveRecord migration helpers to avoid downtime
116
75
  test_files: []
data/.travis.yml DELETED
@@ -1,24 +0,0 @@
1
- language: ruby
2
-
3
- rvm:
4
- - 2.4.1
5
- - 2.3.4
6
- - 2.2.6
7
-
8
- addons:
9
- postgresql: "9.3"
10
-
11
- before_script:
12
- - psql -c 'CREATE DATABASE safer_migrations_test;' -U postgres
13
-
14
- script:
15
- - bundle exec rspec spec
16
- - bundle exec rubocop
17
-
18
- env:
19
- global:
20
- - "DATABASE_URL=postgres://postgres@localhost/safer_migrations_test"
21
- matrix:
22
- - "ACTIVERECORD_VERSION=4.2.9"
23
- - "ACTIVERECORD_VERSION=5.0.5"
24
- - "ACTIVERECORD_VERSION=5.1.3"