Skip to content

Commit 3b05f52

Browse files
committed
Updated lock check to include add_reference method
1 parent be09019 commit 3b05f52

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

lib/strong_migrations/checks.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ def check_add_reference(method, *args)
191191

192192
check_algorithm_option("add_reference", *args, **options)
193193

194+
# not necessarily dangerous, but not necessary
195+
check_lock_option("add_reference", *args, **options)
196+
194197
if (mysql? || mariadb?) && !new_table?(table)
195198
index_value = options[:index]
196199
copy_set = index_value.is_a?(Hash) && index_value[:algorithm] == :copy

test/add_reference_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ def test_algorithm_instant
105105
assert_safe AddReferenceAlgorithmInstant
106106
end
107107

108+
def test_lock_shared
109+
skip unless lock_option?
110+
assert_unsafe AddReferenceLockShared
111+
end
112+
113+
def test_lock_none
114+
skip unless lock_option?
115+
assert_safe AddReferenceLockNone
116+
end
117+
108118
def test_index_algorithm_copy
109119
skip unless mysql? || mariadb?
110120
assert_unsafe AddReferenceIndexAlgorithmCopy

test/migrations/add_reference.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ def change
8484
end
8585
end
8686

87+
class AddReferenceLockShared < TestMigration
88+
def change
89+
add_reference :users, :device, lock: :shared
90+
end
91+
end
92+
93+
class AddReferenceLockNone < TestMigration
94+
def change
95+
add_reference :users, :device, lock: :none
96+
end
97+
end
98+
8799
class AddReferenceIndexAlgorithmCopy < TestMigration
88100
def change
89101
add_reference :users, :device, index: {algorithm: :copy}

0 commit comments

Comments
 (0)