Skip to content

Commit

Permalink
Remove default match in column reference (#172)
Browse files Browse the repository at this point in the history
* - Remove default match

* - Fix tests
  • Loading branch information
charsleysa authored and dolezel committed Feb 5, 2018
1 parent 6ec3ffa commit 577f1ee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/operations/tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const formatLines = (lines, replace, separator = ',\n') =>
const parseReferences = (options) => {
const {
references,
match = 'SIMPLE',
match,
onDelete,
onUpdate,
} = options;
Expand Down
17 changes: 15 additions & 2 deletions test/tables-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,27 @@ describe('lib/operations/tables', () => {
},
});
expect(sql).to.equal(`CREATE TABLE "my_table_name" (
"parent_id" integer REFERENCES "a"."b"
);`);
});

it('check match clause can be used for foreign keys', () => {
const sql = Tables.create()('my_table_name', {
parent_id: {
type: 'integer',
references: { schema: 'a', name: 'b' },
match: 'SIMPLE',
},
});
expect(sql).to.equal(`CREATE TABLE "my_table_name" (
"parent_id" integer REFERENCES "a"."b" MATCH SIMPLE
);`);
});

it('check defining column can be used for foreign keys', () => {
const sql = Tables.create()('my_table_name', { parent_id: { type: 'integer', references: 'a.b(id)' } });
expect(sql).to.equal(`CREATE TABLE "my_table_name" (
"parent_id" integer REFERENCES a.b(id) MATCH SIMPLE
"parent_id" integer REFERENCES a.b(id)
);`);
});

Expand Down Expand Up @@ -76,7 +89,7 @@ describe('lib/operations/tables', () => {
expect(sql).to.equal(`CREATE TABLE "my_table_name" (
"a" integer,
"b" varchar,
FOREIGN KEY ("a", "b") REFERENCES otherTable (A, B) MATCH SIMPLE
FOREIGN KEY ("a", "b") REFERENCES otherTable (A, B)
);`);
});

Expand Down

0 comments on commit 577f1ee

Please sign in to comment.