Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't include schema in primary key constraint name
Browse files Browse the repository at this point in the history
aschrab committed Aug 26, 2017
1 parent c55aaf9 commit 73ed8cc
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/operations/tables.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import _ from 'lodash';
import { escapeValue, template, quote, applyType, applyTypeAdapters } from '../utils';

function parseColumns(columns, table_name, extending_type_shorthands = {}) {
function parseColumns(columns, table, extending_type_shorthands = {}) {
let columnsWithOptions = _.mapValues(
columns,
column => applyType(column, extending_type_shorthands)
);

const table_name = typeof table === 'object' ? table.name : table;

const primaryColumns = _.chain(columnsWithOptions)
.map((options, column_name) => (options.primaryKey ? column_name : null))
.filter()
12 changes: 12 additions & 0 deletions test/tables-test.js
Original file line number Diff line number Diff line change
@@ -28,6 +28,18 @@ describe('lib/operations/tables', () => {
const sql = Tables.create()('my_table_name', { parent_id: { type: 'integer', references: { schema: 'a', name: 'b' } } });
expect(sql).to.equal(`CREATE TABLE "my_table_name" (
"parent_id" integer REFERENCES "a"."b"
);`);
});

it('check multicolumn primary key name does not include schema', () => {
const sql = Tables.create()({ schema: 's', name: 'my_table_name' }, {
a: { type: 'integer', primaryKey: true },
b: { type: 'varchar', primaryKey: true },
});
expect(sql).to.equal(`CREATE TABLE "s"."my_table_name" (
"a" integer,
"b" varchar,
CONSTRAINT "my_table_name_pkey" PRIMARY KEY ("a", "b")
);`);
});
});

0 comments on commit 73ed8cc

Please sign in to comment.