Skip to content

Commit

Permalink
Merge remote-tracking branch 'original/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
steveny committed Feb 5, 2021
2 parents d88952e + 91d5c4d commit 3058c81
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ def column_definitions_sql(database, identifier)
AND c.default_object_id = d.object_id
LEFT OUTER JOIN #{database}.sys.key_constraints k
ON c.object_id = k.parent_object_id
AND k.type = 'PK'
LEFT OUTER JOIN #{database}.sys.index_columns ic
ON k.parent_object_id = ic.object_id
AND k.unique_index_id = ic.index_id
Expand Down
6 changes: 6 additions & 0 deletions test/cases/schema_dumper_test_sqlserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
assert_line :name, type: "string", limit: nil, default: nil, collation: nil
end

it "dumps field with unique key constraints only once" do
output = generate_schema_for_table "unique_key_dumped_table"

_(output.scan('t.integer "unique_field"').length).must_equal(1)
end

private

def generate_schema_for_table(*table_names)
Expand Down
10 changes: 10 additions & 0 deletions test/schema/sqlserver_specific_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,14 @@
field_2 int NOT NULL PRIMARY KEY,
)
SCHEMATESTMULTIPLESCHEMA

execute "IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'unique_key_dumped_table') DROP TABLE unique_key_dumped_table"
execute <<-SQLSERVERUNIQUEKEYS
CREATE TABLE unique_key_dumped_table (
id int IDENTITY(1,1) NOT NULL,
unique_field int DEFAULT 0 NOT NULL,
CONSTRAINT IX_UNIQUE_KEY UNIQUE (unique_field),
CONSTRAINT PK_UNIQUE_KEY PRIMARY KEY (id)
);
SQLSERVERUNIQUEKEYS
end

0 comments on commit 3058c81

Please sign in to comment.