From fcf2082a10e4968b3f1ca24b9511ca530e445334 Mon Sep 17 00:00:00 2001 From: mertmit Date: Sat, 23 Sep 2023 01:47:02 +0300 Subject: [PATCH] fix: SQLite hacky solution for alter table issue Signed-off-by: mertmit --- .../src/db/sql-client/lib/sqlite/SqliteClient.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/nocodb/src/db/sql-client/lib/sqlite/SqliteClient.ts b/packages/nocodb/src/db/sql-client/lib/sqlite/SqliteClient.ts index 3286d79ec6..2ce53a0c44 100644 --- a/packages/nocodb/src/db/sql-client/lib/sqlite/SqliteClient.ts +++ b/packages/nocodb/src/db/sql-client/lib/sqlite/SqliteClient.ts @@ -1619,6 +1619,15 @@ class SqliteClient extends KnexClient { await this.sqlClient.raw('PRAGMA legacy_alter_table = ON;'); + /* + This is a hack to avoid the following error: + - SQLITE_ERROR: duplicate column name: column_name + + Somehow this error is thrown when we drop a column and add a new column with the same name right after it. + TODO - Find a better solution for this. + */ + await this.sqlClient.raw('SELECT * FROM ?? LIMIT 1', [args.table]); + const trx = await this.sqlClient.transaction(); try { @@ -1650,7 +1659,7 @@ class SqliteClient extends KnexClient { await trx.commit(); } catch (e) { await trx.rollback(); - log.ppe(e, _func); + // log.ppe(e, _func); throw e; } finally { if (fkCheckEnabled)