From bfdb463390453a55963af29ef0e7cd3aea26f4cf Mon Sep 17 00:00:00 2001 From: Fabio Di Stasio Date: Thu, 5 May 2022 23:09:10 +0200 Subject: [PATCH] fix: unable to set an empty string as field default --- src/main/libs/clients/MySQLClient.ts | 6 +++--- src/main/libs/clients/PostgreSQLClient.ts | 6 +++--- src/main/libs/clients/SQLiteClient.ts | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/libs/clients/MySQLClient.ts b/src/main/libs/clients/MySQLClient.ts index 4ab9e4a6..3d12d8c9 100644 --- a/src/main/libs/clients/MySQLClient.ts +++ b/src/main/libs/clients/MySQLClient.ts @@ -754,7 +754,7 @@ export class MySQLClient extends AntaresCore { ${field.zerofill ? 'ZEROFILL' : ''} ${field.nullable ? 'NULL' : 'NOT NULL'} ${field.autoIncrement ? 'AUTO_INCREMENT' : ''} - ${field.default ? `DEFAULT ${field.default}` : ''} + ${field.default !== null ? `DEFAULT ${field.default || '\'\''}` : ''} ${field.comment ? `COMMENT '${field.comment}'` : ''} ${field.collation ? `COLLATE ${field.collation}` : ''} ${field.onUpdate ? `ON UPDATE ${field.onUpdate}` : ''}`); @@ -817,7 +817,7 @@ export class MySQLClient extends AntaresCore { ${addition.zerofill ? 'ZEROFILL' : ''} ${addition.nullable ? 'NULL' : 'NOT NULL'} ${addition.autoIncrement ? 'AUTO_INCREMENT' : ''} - ${addition.default ? `DEFAULT ${addition.default}` : ''} + ${addition.default !== null ? `DEFAULT ${addition.default || '\'\''}` : ''} ${addition.comment ? `COMMENT '${addition.comment}'` : ''} ${addition.collation ? `COLLATE ${addition.collation}` : ''} ${addition.onUpdate ? `ON UPDATE ${addition.onUpdate}` : ''} @@ -855,7 +855,7 @@ export class MySQLClient extends AntaresCore { ${change.zerofill ? 'ZEROFILL' : ''} ${change.nullable ? 'NULL' : 'NOT NULL'} ${change.autoIncrement ? 'AUTO_INCREMENT' : ''} - ${change.default ? `DEFAULT ${change.default}` : ''} + ${change.default !== null ? `DEFAULT ${change.default || '\'\''}` : ''} ${change.comment ? `COMMENT '${change.comment}'` : ''} ${change.collation ? `COLLATE ${change.collation}` : ''} ${change.onUpdate ? `ON UPDATE ${change.onUpdate}` : ''} diff --git a/src/main/libs/clients/PostgreSQLClient.ts b/src/main/libs/clients/PostgreSQLClient.ts index d84dd2cb..d42afc57 100644 --- a/src/main/libs/clients/PostgreSQLClient.ts +++ b/src/main/libs/clients/PostgreSQLClient.ts @@ -612,7 +612,7 @@ export class PostgreSQLClient extends AntaresCore { ${field.unsigned ? 'UNSIGNED' : ''} ${field.zerofill ? 'ZEROFILL' : ''} ${field.nullable ? 'NULL' : 'NOT NULL'} - ${field.default ? `DEFAULT ${field.default}` : ''} + ${field.default !== null ? `DEFAULT ${field.default || '\'\''}` : ''} ${field.onUpdate ? `ON UPDATE ${field.onUpdate}` : ''}`); }); @@ -671,7 +671,7 @@ export class PostgreSQLClient extends AntaresCore { ${addition.unsigned ? 'UNSIGNED' : ''} ${addition.zerofill ? 'ZEROFILL' : ''} ${addition.nullable ? 'NULL' : 'NOT NULL'} - ${addition.default ? `DEFAULT ${addition.default}` : ''} + ${addition.default !== null ? `DEFAULT ${addition.default || '\'\''}` : ''} ${addition.onUpdate ? `ON UPDATE ${addition.onUpdate}` : ''}`); }); @@ -715,7 +715,7 @@ export class PostgreSQLClient extends AntaresCore { alterColumns.push(`ALTER COLUMN "${change.name}" TYPE ${localType}${length ? `(${length}${change.numScale ? `,${change.numScale}` : ''})` : ''}${change.isArray ? '[]' : ''} USING "${change.name}"::${localType}`); alterColumns.push(`ALTER COLUMN "${change.name}" ${change.nullable ? 'DROP NOT NULL' : 'SET NOT NULL'}`); - alterColumns.push(`ALTER COLUMN "${change.name}" ${change.default ? `SET DEFAULT ${change.default}` : 'DROP DEFAULT'}`); + alterColumns.push(`ALTER COLUMN "${change.name}" ${change.default !== null ? `SET DEFAULT ${change.default || '\'\''}` : 'DROP DEFAULT'}`); if (['SERIAL', 'SMALLSERIAL', 'BIGSERIAL'].includes(change.type)) { const sequenceName = `${table}_${change.name}_seq`.replace(' ', '_'); diff --git a/src/main/libs/clients/SQLiteClient.ts b/src/main/libs/clients/SQLiteClient.ts index de0b2627..56413aed 100644 --- a/src/main/libs/clients/SQLiteClient.ts +++ b/src/main/libs/clients/SQLiteClient.ts @@ -306,7 +306,7 @@ export class SQLiteClient extends AntaresCore { ${field.unsigned ? 'UNSIGNED' : ''} ${field.nullable ? 'NULL' : 'NOT NULL'} ${field.autoIncrement ? 'AUTO_INCREMENT' : ''} - ${field.default ? `DEFAULT ${field.default}` : ''} + ${field.default !== null ? `DEFAULT ${field.default || '\'\''}` : ''} ${field.onUpdate ? `ON UPDATE ${field.onUpdate}` : ''}`); });