Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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