strong_migrations 1.0.0 → 1.1.0

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: a22e260ec0e3e09954c65535725a3ddc4439b9cf94182a21cf5963e12d8485fe
4
- data.tar.gz: 865633da561d77e615df16a9a00f8524a95bf73edc5590e3932855aaf544d4f7
3
+ metadata.gz: fac153e8505e25b50796c4033952d7e3a0b50db1f0a1fadfd3d3c19e72ac669b
4
+ data.tar.gz: fc7823c9b58f8598f7a5fee9bc9886e6a7cf444cf853da26fb9b6bc960a09dc9
5
5
  SHA512:
6
- metadata.gz: f9b4df7a67aae2c8e1f7c58327b0e7e298261a33d9810dff4b5634bee3e000f1b26e64ad7b3997c8fc6c1cfef3a5cbeabe35ecbe508ed902679e3c9a720ecfb8
7
- data.tar.gz: f4a7ecb6e64c40d1be1025a978387b94b9c2e47897cc25568c32dc32043292bc8fe14c9e6471108a4d84a1b1704459707f4fcf8a25227b7a86d8bcf2237dc19d
6
+ metadata.gz: 4cfb16530dce0d416b54ab87b333926299eaccd84a059d270809fb98a576a489f6d250fe7cb008f9471b0f992819cc6bc9efa90c337c78bd7bb53282cc4758e8
7
+ data.tar.gz: d1aa24bb732b617a4208ac95eafa206c4e3af1782793a7007a89c57894fc2e6a38abccf9e6289f53be1ceda436392bdce08e3cc52be7c70c3b942ea896aaec21
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 1.1.0 (2022-06-08)
2
+
3
+ - Added check for `force` option with `create_join_table`
4
+ - Improved errors for extra arguments
5
+ - Fixed ignoring extra arguments with `safe_by_default`
6
+ - Fixed missing options with `remove_index` and `safe_by_default`
7
+
1
8
  ## 1.0.0 (2022-03-21)
2
9
 
3
10
  New safe operations with MySQL and MariaDB
@@ -33,29 +33,31 @@ module StrongMigrations
33
33
  # see checks.rb for methods
34
34
  case method
35
35
  when :add_check_constraint
36
- check_add_check_constraint(args)
36
+ check_add_check_constraint(*args)
37
37
  when :add_column
38
- check_add_column(args)
38
+ check_add_column(*args)
39
39
  when :add_foreign_key
40
- check_add_foreign_key(args)
40
+ check_add_foreign_key(*args)
41
41
  when :add_index
42
- check_add_index(args)
42
+ check_add_index(*args)
43
43
  when :add_reference, :add_belongs_to
44
- check_add_reference(method, args)
44
+ check_add_reference(method, *args)
45
45
  when :change_column
46
- check_change_column(args)
46
+ check_change_column(*args)
47
47
  when :change_column_null
48
- check_change_column_null(args)
48
+ check_change_column_null(*args)
49
49
  when :change_table
50
50
  check_change_table
51
+ when :create_join_table
52
+ check_create_join_table(*args)
51
53
  when :create_table
52
- check_create_table(args)
54
+ check_create_table(*args)
53
55
  when :execute
54
56
  check_execute
55
57
  when :remove_column, :remove_columns, :remove_timestamps, :remove_reference, :remove_belongs_to
56
- check_remove_column(method, args)
58
+ check_remove_column(method, *args)
57
59
  when :remove_index
58
- check_remove_index(args)
60
+ check_remove_index(*args)
59
61
  when :rename_column
60
62
  check_rename_column
61
63
  when :rename_table
@@ -3,9 +3,9 @@ module StrongMigrations
3
3
  module Checks
4
4
  private
5
5
 
6
- def check_add_check_constraint(args)
7
- table, expression, options = args
8
- options ||= {}
6
+ def check_add_check_constraint(*args)
7
+ options = args.extract_options!
8
+ table, expression = args
9
9
 
10
10
  if !new_table?(table)
11
11
  if postgresql? && options[:validate] != false
@@ -14,7 +14,7 @@ module StrongMigrations
14
14
  validate_options = {name: name}
15
15
 
16
16
  if StrongMigrations.safe_by_default
17
- safe_add_check_constraint(table, expression, add_options, validate_options)
17
+ safe_add_check_constraint(*args, add_options, validate_options)
18
18
  throw :safe
19
19
  end
20
20
 
@@ -27,9 +27,9 @@ module StrongMigrations
27
27
  end
28
28
  end
29
29
 
30
- def check_add_column(args)
31
- table, column, type, options = args
32
- options ||= {}
30
+ def check_add_column(*args)
31
+ options = args.extract_options!
32
+ table, column, type = args
33
33
  default = options[:default]
34
34
 
35
35
  if !default.nil? && !adapter.add_column_default_safe?
@@ -73,14 +73,14 @@ Then add the NOT NULL constraint in separate migrations."
73
73
  #
74
74
  # note: adding foreign_keys with create_table is fine
75
75
  # since the table is always guaranteed to be empty
76
- def check_add_foreign_key(args)
77
- from_table, to_table, options = args
78
- options ||= {}
76
+ def check_add_foreign_key(*args)
77
+ options = args.extract_options!
78
+ from_table, to_table = args
79
79
 
80
80
  validate = options.fetch(:validate, true)
81
81
  if postgresql? && validate
82
82
  if StrongMigrations.safe_by_default
83
- safe_add_foreign_key(from_table, to_table, options)
83
+ safe_add_foreign_key(*args, **options)
84
84
  throw :safe
85
85
  end
86
86
 
@@ -90,9 +90,9 @@ Then add the NOT NULL constraint in separate migrations."
90
90
  end
91
91
  end
92
92
 
93
- def check_add_index(args)
94
- table, columns, options = args
95
- options ||= {}
93
+ def check_add_index(*args)
94
+ options = args.extract_options!
95
+ table, columns = args
96
96
 
97
97
  if columns.is_a?(Array) && columns.size > 3 && !options[:unique]
98
98
  raise_error :add_index_columns, header: "Best practice"
@@ -102,7 +102,7 @@ Then add the NOT NULL constraint in separate migrations."
102
102
  # since the table won't be in use by the application
103
103
  if postgresql? && options[:algorithm] != :concurrently && !new_table?(table)
104
104
  if StrongMigrations.safe_by_default
105
- safe_add_index(table, columns, options)
105
+ safe_add_index(*args, **options)
106
106
  throw :safe
107
107
  end
108
108
 
@@ -110,9 +110,9 @@ Then add the NOT NULL constraint in separate migrations."
110
110
  end
111
111
  end
112
112
 
113
- def check_add_reference(method, args)
114
- table, reference, options = args
115
- options ||= {}
113
+ def check_add_reference(method, *args)
114
+ options = args.extract_options!
115
+ table, reference = args
116
116
 
117
117
  if postgresql?
118
118
  index_value = options.fetch(:index, true)
@@ -127,7 +127,7 @@ Then add the NOT NULL constraint in separate migrations."
127
127
  end
128
128
 
129
129
  if StrongMigrations.safe_by_default
130
- safe_add_reference(table, reference, options)
130
+ safe_add_reference(*args, **options)
131
131
  throw :safe
132
132
  end
133
133
 
@@ -148,9 +148,9 @@ Then add the foreign key in separate migrations."
148
148
  end
149
149
  end
150
150
 
151
- def check_change_column(args)
152
- table, column, type, options = args
153
- options ||= {}
151
+ def check_change_column(*args)
152
+ options = args.extract_options!
153
+ table, column, type = args
154
154
 
155
155
  safe = false
156
156
  existing_column = connection.columns(table).find { |c| c.name.to_s == column.to_s }
@@ -168,7 +168,7 @@ Then add the foreign key in separate migrations."
168
168
  raise_error :change_column, rewrite_blocks: adapter.rewrite_blocks unless safe
169
169
  end
170
170
 
171
- def check_change_column_null(args)
171
+ def check_change_column_null(*args)
172
172
  table, column, null, default = args
173
173
  if !null
174
174
  if postgresql?
@@ -242,13 +242,21 @@ Then add the foreign key in separate migrations."
242
242
  raise_error :change_table, header: "Possibly dangerous operation"
243
243
  end
244
244
 
245
- def check_create_table(args)
246
- table, options = args
247
- options ||= {}
245
+ def check_create_join_table(*args)
246
+ options = args.extract_options!
248
247
 
249
248
  raise_error :create_table if options[:force]
250
249
 
251
- # keep track of new tables of add_index check
250
+ # TODO keep track of new table of add_index check
251
+ end
252
+
253
+ def check_create_table(*args)
254
+ options = args.extract_options!
255
+ table, _ = args
256
+
257
+ raise_error :create_table if options[:force]
258
+
259
+ # keep track of new table of add_index check
252
260
  @new_tables << table.to_s
253
261
  end
254
262
 
@@ -256,7 +264,7 @@ Then add the foreign key in separate migrations."
256
264
  raise_error :execute, header: "Possibly dangerous operation"
257
265
  end
258
266
 
259
- def check_remove_column(method, args)
267
+ def check_remove_column(method, *args)
260
268
  columns =
261
269
  case method
262
270
  when :remove_timestamps
@@ -288,20 +296,26 @@ Then add the foreign key in separate migrations."
288
296
  column_suffix: columns.size > 1 ? "s" : ""
289
297
  end
290
298
 
291
- def check_remove_index(args)
292
- table, options = args
293
- unless options.is_a?(Hash)
294
- options = {column: options}
295
- end
296
- options ||= {}
299
+ def check_remove_index(*args)
300
+ options = args.extract_options!
301
+ table, _ = args
297
302
 
298
303
  if postgresql? && options[:algorithm] != :concurrently && !new_table?(table)
304
+ # avoid suggesting extra (invalid) args
305
+ args = args[0..1] unless StrongMigrations.safe_by_default
306
+
307
+ # Active Record < 6.1 only supports two arguments (including options)
308
+ if args.size == 2 && ar_version < 6.1
309
+ # arg takes precedence over option
310
+ options[:column] = args.pop
311
+ end
312
+
299
313
  if StrongMigrations.safe_by_default
300
- safe_remove_index(table, options)
314
+ safe_remove_index(*args, **options)
301
315
  throw :safe
302
316
  end
303
317
 
304
- raise_error :remove_index, command: command_str("remove_index", [table, options.merge(algorithm: :concurrently)])
318
+ raise_error :remove_index, command: command_str("remove_index", args + [options.merge(algorithm: :concurrently)])
305
319
  end
306
320
  end
307
321
 
@@ -5,22 +5,22 @@ module StrongMigrations
5
5
  end
6
6
 
7
7
  # TODO check if invalid index with expected name exists and remove if needed
8
- def safe_add_index(table, columns, options)
8
+ def safe_add_index(*args, **options)
9
9
  disable_transaction
10
- @migration.add_index(table, columns, **options.merge(algorithm: :concurrently))
10
+ @migration.add_index(*args, **options.merge(algorithm: :concurrently))
11
11
  end
12
12
 
13
- def safe_remove_index(table, options)
13
+ def safe_remove_index(*args, **options)
14
14
  disable_transaction
15
- @migration.remove_index(table, **options.merge(algorithm: :concurrently))
15
+ @migration.remove_index(*args, **options.merge(algorithm: :concurrently))
16
16
  end
17
17
 
18
- def safe_add_reference(table, reference, options)
18
+ def safe_add_reference(table, reference, *args, **options)
19
19
  @migration.reversible do |dir|
20
20
  dir.up do
21
21
  disable_transaction
22
22
  foreign_key = options.delete(:foreign_key)
23
- @migration.add_reference(table, reference, **options)
23
+ @migration.add_reference(table, reference, *args, **options)
24
24
  if foreign_key
25
25
  # same as Active Record
26
26
  name =
@@ -43,10 +43,10 @@ module StrongMigrations
43
43
  end
44
44
  end
45
45
 
46
- def safe_add_foreign_key(from_table, to_table, options)
46
+ def safe_add_foreign_key(from_table, to_table, *args, **options)
47
47
  @migration.reversible do |dir|
48
48
  dir.up do
49
- @migration.add_foreign_key(from_table, to_table, **options.merge(validate: false))
49
+ @migration.add_foreign_key(from_table, to_table, *args, **options.merge(validate: false))
50
50
  disable_transaction
51
51
  @migration.validate_foreign_key(from_table, to_table)
52
52
  end
@@ -56,10 +56,10 @@ module StrongMigrations
56
56
  end
57
57
  end
58
58
 
59
- def safe_add_check_constraint(table, expression, add_options, validate_options)
59
+ def safe_add_check_constraint(table, expression, *args, add_options, validate_options)
60
60
  @migration.reversible do |dir|
61
61
  dir.up do
62
- @migration.add_check_constraint(table, expression, **add_options)
62
+ @migration.add_check_constraint(table, expression, *args, **add_options)
63
63
  disable_transaction
64
64
  @migration.validate_check_constraint(table, **validate_options)
65
65
  end
@@ -1,3 +1,3 @@
1
1
  module StrongMigrations
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
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.0.0
4
+ version: 1.1.0
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-03-21 00:00:00.000000000 Z
13
+ date: 2022-06-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord