pg_ha_migrations 1.6.0 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -45,6 +45,8 @@ module PgHaMigrations::UnsafeStatements
45
45
  delegate_unsafe_method_to_migration_base_class :remove_index
46
46
  delegate_unsafe_method_to_migration_base_class :add_foreign_key
47
47
  delegate_unsafe_method_to_migration_base_class :remove_foreign_key
48
+ delegate_unsafe_method_to_migration_base_class :add_check_constraint
49
+ delegate_unsafe_method_to_migration_base_class :remove_check_constraint
48
50
 
49
51
  disable_or_delegate_default_method :create_table, ":create_table is NOT SAFE! Use safe_create_table instead"
50
52
  disable_or_delegate_default_method :add_column, ":add_column is NOT SAFE! Use safe_add_column instead"
@@ -61,6 +63,8 @@ module PgHaMigrations::UnsafeStatements
61
63
  disable_or_delegate_default_method :remove_index, ":remove_index is NOT SAFE! Use safe_remove_concurrent_index instead for Postgres 9.6 databases; Explicitly call :unsafe_remove_index to proceed on Postgres 9.1"
62
64
  disable_or_delegate_default_method :add_foreign_key, ":add_foreign_key is NOT SAFE! Explicitly call :unsafe_add_foreign_key"
63
65
  disable_or_delegate_default_method :remove_foreign_key, ":remove_foreign_key is NOT SAFE! Explicitly call :unsafe_remove_foreign_key"
66
+ disable_or_delegate_default_method :add_check_constraint, ":add_check_constraint is NOT SAFE! Use :safe_add_unvalidated_check_constraint and then :safe_validate_check_constraint instead"
67
+ disable_or_delegate_default_method :remove_check_constraint, ":remove_check_constraint is NOT SAFE! Explicitly call :unsafe_remove_check_constraint to proceed"
64
68
 
65
69
  def unsafe_create_table(table, options={}, &block)
66
70
  if options[:force] && !PgHaMigrations.config.allow_force_create_table
@@ -76,6 +80,16 @@ module PgHaMigrations::UnsafeStatements
76
80
  raise PgHaMigrations::InvalidMigrationError, "ActiveRecord drops the :opclass option when supplying a string containing an expression or list of columns; instead either supply an array of columns or include the opclass in the string for each column"
77
81
  end
78
82
 
83
+ validated_table = PgHaMigrations::Table.from_table_name(table)
84
+
85
+ validated_index = if options[:name]
86
+ PgHaMigrations::Index.new(options[:name], validated_table)
87
+ else
88
+ PgHaMigrations::Index.from_table_and_columns(validated_table, column_names)
89
+ end
90
+
91
+ options[:name] = validated_index.name
92
+
79
93
  execute_ancestor_statement(:add_index, table, column_names, **options)
80
94
  end
81
95
 
@@ -1,3 +1,3 @@
1
1
  module PgHaMigrations
2
- VERSION = "1.6.0"
2
+ VERSION = "1.8.0"
3
3
  end
@@ -2,6 +2,8 @@ require "pg_ha_migrations/version"
2
2
  require "rails"
3
3
  require "active_record"
4
4
  require "active_record/migration"
5
+ require "active_record/connection_adapters/postgresql/utils"
6
+ require "active_support/core_ext/numeric/bytes"
5
7
  require "relation_to_struct"
6
8
  require "ruby2_keywords"
7
9
 
@@ -10,7 +12,8 @@ module PgHaMigrations
10
12
  :disable_default_migration_methods,
11
13
  :check_for_dependent_objects,
12
14
  :allow_force_create_table,
13
- :prefer_single_step_column_addition_with_default
15
+ :prefer_single_step_column_addition_with_default,
16
+ :infer_primary_key_on_partitioned_tables,
14
17
  )
15
18
 
16
19
  def self.config
@@ -18,7 +21,8 @@ module PgHaMigrations
18
21
  true,
19
22
  false,
20
23
  true,
21
- false
24
+ false,
25
+ true
22
26
  )
23
27
  end
24
28
 
@@ -28,6 +32,17 @@ module PgHaMigrations
28
32
 
29
33
  LOCK_TIMEOUT_SECONDS = 5
30
34
  LOCK_FAILURE_RETRY_DELAY_MULTLIPLIER = 5
35
+ SMALL_TABLE_THRESHOLD_BYTES = 10.megabytes
36
+
37
+ PARTITION_TYPES = %i[range list hash]
38
+
39
+ PARTMAN_UPDATE_CONFIG_OPTIONS = %i[
40
+ infinite_time_partitions
41
+ inherit_privileges
42
+ premake
43
+ retention
44
+ retention_keep_table
45
+ ]
31
46
 
32
47
  # Safe versus unsafe in this context specifically means the following:
33
48
  # - Safe operations will not block for long periods of time.
@@ -42,7 +57,7 @@ module PgHaMigrations
42
57
  # raise this error. For example, adding a column without a default and
43
58
  # then setting its default in a second action in a single migration
44
59
  # isn't our documented best practice and will raise this error.
45
- BestPracticeError = Class.new(Exception)
60
+ BestPracticeError = Class.new(StandardError)
46
61
 
47
62
  # Unsupported migrations use ActiveRecord::Migration features that
48
63
  # we don't support, and therefore will likely have unexpected behavior.
@@ -50,10 +65,17 @@ module PgHaMigrations
50
65
 
51
66
  # This gem only supports the PostgreSQL adapter at this time.
52
67
  UnsupportedAdapter = Class.new(StandardError)
68
+
69
+ # Some methods need to inspect the attributes of a table. In such cases,
70
+ # this error will be raised if the table does not exist
71
+ UndefinedTableError = Class.new(StandardError)
53
72
  end
54
73
 
74
+ require "pg_ha_migrations/relation"
55
75
  require "pg_ha_migrations/blocking_database_transactions"
56
76
  require "pg_ha_migrations/blocking_database_transactions_reporter"
77
+ require "pg_ha_migrations/partman_config"
78
+ require "pg_ha_migrations/lock_mode"
57
79
  require "pg_ha_migrations/unsafe_statements"
58
80
  require "pg_ha_migrations/safe_statements"
59
81
  require "pg_ha_migrations/dependent_objects_checks"
@@ -61,6 +83,7 @@ require "pg_ha_migrations/allowed_versions"
61
83
  require "pg_ha_migrations/railtie"
62
84
  require "pg_ha_migrations/hacks/disable_ddl_transaction"
63
85
  require "pg_ha_migrations/hacks/cleanup_unnecessary_output"
86
+ require "pg_ha_migrations/hacks/add_index_on_only"
64
87
 
65
88
  module PgHaMigrations::AutoIncluder
66
89
  def inherited(klass)
@@ -32,12 +32,12 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency "rake", ">= 12.3.3"
33
33
  spec.add_development_dependency "rspec", "~> 3.0"
34
34
  spec.add_development_dependency "pg"
35
- spec.add_development_dependency "db-query-matchers", "~> 0.11.0"
35
+ spec.add_development_dependency "db-query-matchers", "~> 0.12.0"
36
36
  spec.add_development_dependency "pry"
37
37
  spec.add_development_dependency "pry-byebug"
38
38
  spec.add_development_dependency "appraisal", "~> 2.2.0"
39
39
 
40
- spec.add_dependency "rails", ">= 5.0", "< 7.1"
40
+ spec.add_dependency "rails", ">= 6.1", "< 7.2"
41
41
  spec.add_dependency "relation_to_struct", ">= 1.5.1"
42
42
  spec.add_dependency "ruby2_keywords"
43
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_ha_migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - celeen
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: exe
16
16
  cert_chain: []
17
- date: 2022-07-15 00:00:00.000000000 Z
17
+ date: 2024-01-12 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: rake
@@ -64,14 +64,14 @@ dependencies:
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: 0.11.0
67
+ version: 0.12.0
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: 0.11.0
74
+ version: 0.12.0
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: pry
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -120,20 +120,20 @@ dependencies:
120
120
  requirements:
121
121
  - - ">="
122
122
  - !ruby/object:Gem::Version
123
- version: '5.0'
123
+ version: '6.1'
124
124
  - - "<"
125
125
  - !ruby/object:Gem::Version
126
- version: '7.1'
126
+ version: '7.2'
127
127
  type: :runtime
128
128
  prerelease: false
129
129
  version_requirements: !ruby/object:Gem::Requirement
130
130
  requirements:
131
131
  - - ">="
132
132
  - !ruby/object:Gem::Version
133
- version: '5.0'
133
+ version: '6.1'
134
134
  - - "<"
135
135
  - !ruby/object:Gem::Version
136
- version: '7.1'
136
+ version: '7.2'
137
137
  - !ruby/object:Gem::Dependency
138
138
  name: relation_to_struct
139
139
  requirement: !ruby/object:Gem::Requirement
@@ -177,27 +177,30 @@ files:
177
177
  - ".ruby-version"
178
178
  - Appraisals
179
179
  - CODE_OF_CONDUCT.md
180
+ - Dockerfile
180
181
  - Gemfile
181
182
  - LICENSE.txt
182
183
  - README.md
183
184
  - Rakefile
184
185
  - bin/console
185
186
  - bin/setup
187
+ - docker-compose.yml
186
188
  - gemfiles/.bundle/config
187
- - gemfiles/rails_5.0.gemfile
188
- - gemfiles/rails_5.1.gemfile
189
- - gemfiles/rails_5.2.gemfile
190
- - gemfiles/rails_6.0.gemfile
191
189
  - gemfiles/rails_6.1.gemfile
192
190
  - gemfiles/rails_7.0.gemfile
191
+ - gemfiles/rails_7.1.gemfile
193
192
  - lib/pg_ha_migrations.rb
194
193
  - lib/pg_ha_migrations/allowed_versions.rb
195
194
  - lib/pg_ha_migrations/blocking_database_transactions.rb
196
195
  - lib/pg_ha_migrations/blocking_database_transactions_reporter.rb
197
196
  - lib/pg_ha_migrations/dependent_objects_checks.rb
197
+ - lib/pg_ha_migrations/hacks/add_index_on_only.rb
198
198
  - lib/pg_ha_migrations/hacks/cleanup_unnecessary_output.rb
199
199
  - lib/pg_ha_migrations/hacks/disable_ddl_transaction.rb
200
+ - lib/pg_ha_migrations/lock_mode.rb
201
+ - lib/pg_ha_migrations/partman_config.rb
200
202
  - lib/pg_ha_migrations/railtie.rb
203
+ - lib/pg_ha_migrations/relation.rb
201
204
  - lib/pg_ha_migrations/safe_statements.rb
202
205
  - lib/pg_ha_migrations/unsafe_statements.rb
203
206
  - lib/pg_ha_migrations/version.rb
@@ -222,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
225
  - !ruby/object:Gem::Version
223
226
  version: '0'
224
227
  requirements: []
225
- rubygems_version: 3.1.4
228
+ rubygems_version: 3.2.3
226
229
  signing_key:
227
230
  specification_version: 4
228
231
  summary: Enforces DDL/migration safety in Ruby on Rails project with an emphasis on
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "5.0.7.2"
6
-
7
- gemspec path: "../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "5.2.3"
6
-
7
- gemspec path: "../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "6.0.0"
6
-
7
- gemspec path: "../"