Skip to content

Commit b15f570

Browse files
author
Amr
committed
fix(drizzle-kit): fix silent failure when schema has duplicate entities
- Fixed wrong variable (errors vs errors2) being logged in error handlers - postgres/serializer.ts: errors -> errors2 - cockroach/serializer.ts: errors -> errors2 - generate-mssql.ts: errors -> errors2 - push-mssql.ts: errors -> errors1/errors2 - Added missing error type handlers in postgresSchemaError(): - table_name_duplicate - column_name_duplicate - schema_name_duplicate - enum_name_duplicate - enum_values_duplicate - role_duplicate - privilege_duplicate
1 parent fc31a5f commit b15f570

File tree

5 files changed

+41
-5
lines changed

5 files changed

+41
-5
lines changed

drizzle-kit/src/cli/commands/generate-mssql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export const handleExport = async (config: ExportConfig) => {
101101

102102
const { ddl, errors: errors2 } = interimToDDL(schema);
103103
if (errors2.length > 0) {
104-
console.log(errors.map((it) => mssqlSchemaError(it)).join('\n'));
104+
console.log(errors2.map((it) => mssqlSchemaError(it)).join('\n'));
105105
process.exit(1);
106106
}
107107

drizzle-kit/src/cli/commands/push-mssql.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ export const handle = async (
6767
const { ddl: ddl2, errors: errors2 } = interimToDDL(schemaTo);
6868

6969
if (errors1.length > 0) {
70-
console.log(errors.map((it) => mssqlSchemaError(it)).join('\n'));
70+
console.log(errors1.map((it) => mssqlSchemaError(it)).join('\n'));
7171
process.exit(1);
7272
}
7373

7474
if (errors2.length > 0) {
75-
console.log(errors.map((it) => mssqlSchemaError(it)).join('\n'));
75+
console.log(errors2.map((it) => mssqlSchemaError(it)).join('\n'));
7676
process.exit(1);
7777
}
7878

drizzle-kit/src/cli/views.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,42 @@ export const postgresSchemaError = (error: PostgresSchemaError): string => {
923923
return withStyle.errorWarning(`There's a sequence name duplicate '${error.name}' in '${error.schema}' schema`);
924924
}
925925

926+
if (error.type === 'table_name_duplicate') {
927+
const { schema, name } = error;
928+
return withStyle.errorWarning(
929+
`There's a duplicate table name '${name}' in '${schema}' schema. This can happen if you export the same table under multiple names.`,
930+
);
931+
}
932+
933+
if (error.type === 'column_name_duplicate') {
934+
const { schema, table, name } = error;
935+
return withStyle.errorWarning(
936+
`There's a duplicate column name '${name}' in '${schema}.${table}' table.`,
937+
);
938+
}
939+
940+
if (error.type === 'schema_name_duplicate') {
941+
return withStyle.errorWarning(`There's a duplicate schema name '${error.name}'.`);
942+
}
943+
944+
if (error.type === 'enum_name_duplicate') {
945+
const { schema, name } = error;
946+
return withStyle.errorWarning(`There's a duplicate enum name '${name}' in '${schema}' schema.`);
947+
}
948+
949+
if (error.type === 'enum_values_duplicate') {
950+
const { schema, name } = error;
951+
return withStyle.errorWarning(`There are duplicate values in enum '${name}' in '${schema}' schema.`);
952+
}
953+
954+
if (error.type === 'role_duplicate') {
955+
return withStyle.errorWarning(`There's a duplicate role name '${error.name}'.`);
956+
}
957+
958+
if (error.type === 'privilege_duplicate') {
959+
return withStyle.errorWarning(`There's a duplicate privilege '${error.name}'.`);
960+
}
961+
926962
// assertUnreachable(error);
927963
return '';
928964
};

drizzle-kit/src/dialects/cockroach/serializer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const prepareSnapshot = async (
4949
const { ddl: ddlCur, errors: errors2 } = interimToDDL(schema);
5050

5151
if (errors2.length > 0) {
52-
console.log(errors.map((it) => postgresSchemaError(it)).join('\n'));
52+
console.log(errors2.map((it) => postgresSchemaError(it)).join('\n'));
5353
process.exit(1);
5454
}
5555

drizzle-kit/src/dialects/postgres/serializer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const prepareSnapshot = async (
4949
const { ddl: ddlCur, errors: errors2 } = interimToDDL(schema);
5050

5151
if (errors2.length > 0) {
52-
console.log(errors.map((it) => postgresSchemaError(it)).join('\n'));
52+
console.log(errors2.map((it) => postgresSchemaError(it)).join('\n'));
5353
process.exit(1);
5454
}
5555

0 commit comments

Comments
 (0)