Browse Source

fix: sqlite3 drop column query

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/4280/head
mertmit 2 years ago
parent
commit
558f0552ff
  1. 34
      packages/nocodb/src/lib/db/sql-client/lib/sqlite/SqliteClient.ts

34
packages/nocodb/src/lib/db/sql-client/lib/sqlite/SqliteClient.ts

@ -1491,7 +1491,7 @@ class SqliteClient extends KnexClient {
if (args.columns[i].altered & 4) { if (args.columns[i].altered & 4) {
// col remove // col remove
upQuery += await this.alterTableRemoveColumn( upQuery += this.alterTableRemoveColumn(
args.table, args.table,
args.columns[i], args.columns[i],
oldColumn, oldColumn,
@ -1546,18 +1546,7 @@ class SqliteClient extends KnexClient {
); );
//downQuery += alterTablePK(args.originalColumns, args.columns, downQuery); //downQuery += alterTablePK(args.originalColumns, args.columns, downQuery);
if (upQuery) { await this.sqlClient.raw(upQuery);
//upQuery = `ALTER TABLE ${args.columns[0].tn} ${upQuery};`;
//downQuery = `ALTER TABLE ${args.columns[0].tn} ${downQuery};`;
}
await Promise.all(
upQuery.split(';').map(async (query) => {
if (query.trim().length) await this.sqlClient.raw(query);
})
);
// await this.sqlClient.raw(upQuery);
console.log(upQuery); console.log(upQuery);
@ -1912,16 +1901,15 @@ class SqliteClient extends KnexClient {
return query; return query;
} }
async alterTableRemoveColumn(t, n, _o, _existingQuery) { alterTableRemoveColumn(t, n, _o, existingQuery) {
// let query = existingQuery ? "," : ""; const shouldSanitize = true;
// query += ` DROP COLUMN ${n.cn}`; let query = existingQuery ? ';' : '';
// query = existingQuery ? query : `ALTER TABLE "${t}" ${query};`; query += this.genQuery(
// return query; `ALTER TABLE ?? DROP COLUMN ??`,
await this.sqlClient.schema.alterTable(t, (tb) => { [t, n.cn],
tb.dropColumn(n.cn); shouldSanitize
}); );
return query;
return '';
} }
createTableColumn(t, n, o, existingQuery) { createTableColumn(t, n, o, existingQuery) {

Loading…
Cancel
Save