Skip to content

Commit

Permalink
Merge be8cb6b into 1ef1a4e
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanovych666 committed Aug 25, 2019
2 parents 1ef1a4e + be8cb6b commit 5a97d14
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dialects/postgres/schema/columncompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Object.assign(ColumnCompiler_PG.prototype, {
let enumName = '';
const schemaName = this.tableCompiler.schemaNameRaw;

if (schemaName) {
if (schemaName && !options.enumName.includes('.')) {
enumName += `"${schemaName}".`;
}

Expand Down
50 changes: 50 additions & 0 deletions test/unit/schema/postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,56 @@ describe('PostgreSQL SchemaBuilder', function() {
);
});

it('adding enum with useNative, from manually defined schema and withSchema', function() {
const tableSchema = 'table_schema';
const tableName = 'table_name';
const typeSchema = 'type_schema';
const typeName = 'type_name';
const columnName = 'column_name';

tableSql = client
.schemaBuilder()
.withSchema(tableSchema)
.table(tableName, function(table) {
table.enu(columnName, ['foo', 'bar', 'baz'], {
useNative: true,
enumName: `${typeSchema}.${typeName}`,
});
})
.toSQL();
equal(2, tableSql.length);
expect(tableSql[0].sql).to.equal(
`create type "${typeSchema}.${typeName}" as enum ('foo', 'bar', 'baz')`
);
expect(tableSql[1].sql).to.equal(
`alter table "${tableSchema}"."${tableName}" add column "${columnName}" "${typeSchema}.${typeName}"`
);
});

it('adding enum with useNative and existingType, from manually defined schema and withSchema', function() {
const tableSchema = 'table_schema';
const tableName = 'table_name';
const typeSchema = 'type_schema';
const typeName = 'type_name';
const columnName = 'column_name';

tableSql = client
.schemaBuilder()
.withSchema(tableSchema)
.table(tableName, function(table) {
table.enu(columnName, null, {
useNative: true,
enumName: `${typeSchema}.${typeName}`,
existingType: true,
});
})
.toSQL();
equal(1, tableSql.length);
expect(tableSql[0].sql).to.equal(
`alter table "${tableSchema}"."${tableName}" add column "${columnName}" "${typeSchema}.${typeName}"`
);
});

it('adding date', function() {
tableSql = client
.schemaBuilder()
Expand Down

0 comments on commit 5a97d14

Please sign in to comment.