fix: do not insert second id column

This commit is contained in:
Nybkox
2025-02-06 09:39:49 +01:00
parent 1d1e488755
commit 13ee14c752

View File

@@ -27,6 +27,8 @@ function getColumnInfo(tableInfo, columnName) {
* @returns {{ shouldAddUuidPk: true, pkColumnName: string } | { shouldAddUuidPk: false }}
*/
function getShouldAddUuidPkInfo(tableInfo) {
const hasIdColumn = tableInfo.columns.some((x) => x.columnName == 'id');
if (hasIdColumn && !tableInfo.primaryKey) return { shouldAddUuidPk: false };
const pkColumnName = tableInfo.primaryKey?.columns[0]?.columnName;
if (!pkColumnName) return { shouldAddUuidPk: true, pkColumnName: 'id' };
@@ -72,7 +74,7 @@ function createCassandraBulkInsertStream(driver, stream, dbhan, name, options) {
dmp.putRaw('uuid()');
dmp.putRaw(', ');
}
dmp.putCollection(',', writable.columnNames, (col) => dmp.putValue(row[col]));
dmp.putCollection(',', writable.columnNames, (col) => dmp.putValue(row[col]?.toString()));
dmp.putRaw(')');
await driver.query(dbhan, dmp.s, { discardResult: true });
}