fix: column primary key toggling errors

Co-authored-by: phunguyenmurcul <51897872+phunguyenmurcul@users.noreply.github.com>
This commit is contained in:
gitstartandphunguyenmurcul committed 2023-04-12 16:58:12 +00:00
1 parent 9c3cd02b9f
commit 9c54876f43
1 file changed
+8 -4
+8 -4
View File
@@ -288,8 +288,8 @@ export default class MetaStore implements IMetaStore {
}
async addPrimaryKey(schema: string, table: string, columns: string[]) {
const primaryKeyColumns = columns.join(',')
const query = `ALTER TABLE "${schema}"."${table}" ADD PRIMARY KEY (${primaryKeyColumns})`
const primaryKeyColumns = columns.join('","')
const query = `ALTER TABLE "${schema}"."${table}" ADD PRIMARY KEY ("${primaryKeyColumns}")`
return await this.query(query)
}
@@ -501,11 +501,15 @@ export default class MetaStore implements IMetaStore {
const removePK = await this.removePrimaryKey(column.schema, column.table)
if (removePK.error) throw removePK.error
}
const primaryKeyColumns = isPrimaryKey
? existingPrimaryKeys.concat([column.name])
: existingPrimaryKeys.filter((x) => x !== column.name)
const addPK = await this.addPrimaryKey(column.schema, column.table, primaryKeyColumns)
if (addPK.error) throw addPK.error
if (primaryKeyColumns.length) {
const addPK = await this.addPrimaryKey(column.schema, column.table, primaryKeyColumns)
if (addPK.error) throw addPK.error
}
}
// For updating of foreign key relationship, we remove the original one by default