mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 14:43:06 +08:00
fix(base): declare primary key on loaded rows so upsert has a conflict target
This commit is contained in:
@@ -85,6 +85,12 @@ export class CollectionLoader {
|
||||
// Postgres; all subsequent queries run purely against the local table.
|
||||
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.
|
||||
for (const spec of specs) {
|
||||
if (!spec.indexable) continue;
|
||||
|
||||
Reference in New Issue
Block a user