fix(base): declare primary key on loaded rows so upsert has a conflict target

This commit is contained in:
Philipinho
2026-04-23 14:31:26 +01:00
parent 5b96dfe6c9
commit 709d927544
@@ -85,6 +85,12 @@ export class CollectionLoader {
// Postgres; all subsequent queries run purely against the local table. // Postgres; all subsequent queries run purely against the local table.
await this.pgExtension.detach(connection); await this.pgExtension.detach(connection);
// CREATE TABLE AS copies data but not constraints. Re-declare the primary
// key so INSERT OR REPLACE (used by applyChange.upsertRow) has a conflict
// target. This also backs id lookups with an implicit index, speeding up
// per-row upsert/delete.
await connection.run('ALTER TABLE rows ADD PRIMARY KEY (id)');
// Build ART indexes on indexable columns. // Build ART indexes on indexable columns.
for (const spec of specs) { for (const spec of specs) {
if (!spec.indexable) continue; if (!spec.indexable) continue;