Skip to content

Commit 21ab578

Browse files
committed
fix(sql-driver): avoid duplicate-column errors by skipping built-in columns during table creation
1 parent 3bb2c21 commit 21ab578

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

packages/plugins/driver-sql/src/sql-driver.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,13 +611,19 @@ export class SqlDriver implements IDataDriver {
611611
}
612612
}
613613

614+
// Columns created unconditionally by initObjects — skip them when
615+
// iterating obj.fields to avoid duplicate-column errors (e.g. SQLite
616+
// rejects CREATE TABLE with two columns of the same name).
617+
const builtinColumns = new Set(['id', 'created_at', 'updated_at']);
618+
614619
if (!exists) {
615620
await this.knex.schema.createTable(tableName, (table) => {
616621
table.string('id').primary();
617622
table.timestamp('created_at').defaultTo(this.knex.fn.now());
618623
table.timestamp('updated_at').defaultTo(this.knex.fn.now());
619624
if (obj.fields) {
620625
for (const [name, field] of Object.entries(obj.fields)) {
626+
if (builtinColumns.has(name)) continue;
621627
this.createColumn(table, name, field);
622628
}
623629
}

0 commit comments

Comments
 (0)