strong_migrations 1.3.0 → 1.3.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: 4da88a3161110bc4e7fd6cc989ea51e0db2e32681c8026db11ac74c763f253b3
4
- data.tar.gz: 583cd8b1e9665842ff6017c6d7242dcbfd9583157327b33ec023d5357c4e799f
3
+ metadata.gz: b330db9323d9942a9e24a5fdc3ab75931030f859505cb9eef2f428df840b4dcc
4
+ data.tar.gz: 8aa1acd2debbc49206cf9b3928c16e85d4f2f47140142d4e9b981d1d54254e12
5
5
  SHA512:
6
- metadata.gz: 68356a9f5966f33a2a43f35a5f74ce21943798e4d85eb1c52710808dbac0efab6659d67a22d89aa4360cfc4f87e0dce6312e16f3a71dc0a739e87bb335d42f84
7
- data.tar.gz: 67038470a20b75fd3dfb8642fea4775aedb08bff959255a44aa92271e2214300e9140f3d7cce21eae83e81ea314739c06999ce8d46a72f76f75f675e6c8914fb
6
+ metadata.gz: 2bce01385b02f0c005cae82cda4325f5332b400949cc0c5814a25c4bc30f78ff0a66730179dc52458bae242aa5cc4d1eb6be755696c731521580b3554f3eee6c
7
+ data.tar.gz: 72bcd4096a69bd3c8afd78caa43651b10bf5924318635adeb52308724751fa9fdbaeaa59e07a690a4a0915524afbab3487a8f1db17086c18e0b742c0d3de6b28
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.3.1 (2022-09-21)
2
+
3
+ - Fixed check for `add_column` with `default: nil` with Postgres 10
4
+
1
5
  ## 1.3.0 (2022-08-30)
2
6
 
3
7
  - Added check for `add_column` with `uuid` type and volatile default value
@@ -32,9 +32,11 @@ module StrongMigrations
32
32
  table, column, type = args
33
33
  default = options[:default]
34
34
 
35
- # Active Record has special case for uuid columns that allows function default values
35
+ # Check key since DEFAULT NULL behaves differently from no default
36
+ #
37
+ # Also, Active Record has special case for uuid columns that allows function default values
36
38
  # https://github.com/rails/rails/blob/v7.0.3.1/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb#L92-L93
37
- if !default.nil? && (!adapter.add_column_default_safe? || (volatile = (postgresql? && type.to_s == "uuid" && default.to_s.include?("()") && adapter.default_volatile?(default))))
39
+ if options.key?(:default) && (!adapter.add_column_default_safe? || (volatile = (postgresql? && type.to_s == "uuid" && default.to_s.include?("()") && adapter.default_volatile?(default))))
38
40
  if options[:null] == false
39
41
  options = options.except(:null)
40
42
  append = "
@@ -222,9 +224,7 @@ Then add the foreign key in separate migrations."
222
224
 
223
225
  add_constraint_code =
224
226
  if constraint_methods
225
- # only quote when needed
226
- expr_column = column.to_s =~ /\A[a-z0-9_]+\z/ ? column : connection.quote_column_name(column)
227
- command_str(:add_check_constraint, [table, "#{expr_column} IS NOT NULL", {name: constraint_name, validate: false}])
227
+ command_str(:add_check_constraint, [table, "#{quote_column_if_needed(column)} IS NOT NULL", {name: constraint_name, validate: false}])
228
228
  else
229
229
  safety_assured_str(add_code)
230
230
  end
@@ -424,12 +424,19 @@ Then add the foreign key in separate migrations."
424
424
  model = table.to_s.classify
425
425
  if function
426
426
  # update_all(column: Arel.sql(default)) also works in newer versions of Active Record
427
- "#{model}.unscoped.in_batches do |relation| \n relation.where(#{column}: nil).update_all(\"#{column} = #{default}\")\n sleep(0.01)\n end"
427
+ update_expr = "#{quote_column_if_needed(column)} = #{default}"
428
+ "#{model}.unscoped.in_batches do |relation| \n relation.where(#{column}: nil).update_all(#{update_expr.inspect})\n sleep(0.01)\n end"
428
429
  else
429
430
  "#{model}.unscoped.in_batches do |relation| \n relation.update_all #{column}: #{default.inspect}\n sleep(0.01)\n end"
430
431
  end
431
432
  end
432
433
 
434
+ # only quote when needed
435
+ # important! only use for display purposes
436
+ def quote_column_if_needed(column)
437
+ column.to_s =~ /\A[a-z0-9_]+\z/ ? column : connection.quote_column_name(column)
438
+ end
439
+
433
440
  def new_table?(table)
434
441
  @new_tables.include?(table.to_s)
435
442
  end
@@ -1,3 +1,3 @@
1
1
  module StrongMigrations
2
- VERSION = "1.3.0"
2
+ VERSION = "1.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strong_migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-08-30 00:00:00.000000000 Z
13
+ date: 2022-09-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord