-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added check for add_unique_constraint - closes #252
- Loading branch information
Showing
7 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require_relative "test_helper" | ||
|
||
class AddUniqueConstraintTest < Minitest::Test | ||
def setup | ||
skip unless unique_constraints? | ||
super | ||
end | ||
|
||
def test_basic | ||
assert_unsafe AddUniqueConstraint | ||
end | ||
|
||
def test_using_index | ||
assert_safe AddUniqueConstraintUsingIndex | ||
end | ||
|
||
def test_new_table | ||
assert_safe AddUniqueConstraintNewTable | ||
end | ||
|
||
def unique_constraints? | ||
postgresql? && ActiveRecord::VERSION::STRING.to_f >= 7.1 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class AddUniqueConstraint < TestMigration | ||
def change | ||
add_unique_constraint :users, :name | ||
end | ||
end | ||
|
||
class AddUniqueConstraintUsingIndex < TestMigration | ||
disable_ddl_transaction! | ||
|
||
def up | ||
add_index :users, :name, unique: true, algorithm: :concurrently | ||
add_unique_constraint :users, using_index: "index_users_on_name" | ||
end | ||
|
||
def down | ||
remove_unique_constraint :users, :name | ||
end | ||
end | ||
|
||
class AddUniqueConstraintNewTable < TestMigration | ||
def change | ||
create_table :new_users do |t| | ||
t.string :name | ||
end | ||
|
||
add_unique_constraint :new_users, :name | ||
end | ||
end |