Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

docs(migrations): correct the lock and timeout notes on index builds

Yudhi Armyndharis36e9d4b40557
diff --git a/src/database/migrations/1785123853000-AddMessagesCreatedAtIndex.ts b/src/database/migrations/1785123853000-AddMessagesCreatedAtIndex.ts
index 9643228fa..902c4595f 100644
--- a/src/database/migrations/1785123853000-AddMessagesCreatedAtIndex.ts
+++ b/src/database/migrations/1785123853000-AddMessagesCreatedAtIndex.ts
@@ -12,13 +12,14 @@ import { MigrationInterface, QueryRunner } from 'typeorm';
* `synchronize` already created the same-named index declared on the Message entity.
*
* The `messages` table is the hottest data table (every inbound/outbound row), so on Postgres a
- * CREATE INDEX over a large table at boot can exceed the runtime pool's statement_timeout and abort
- * the migration. Lift it for THIS transaction (SET LOCAL auto-reverts at COMMIT; SQLite rejects it
- * syntactically, hence the guard) — the same discipline AddWebhooksSessionIdIndex and
- * AddMessagesWaMessageIdUnique already use. `CONCURRENTLY` would avoid the ACCESS EXCLUSIVE lock
- * but cannot run inside a transaction, so it is deliberately NOT used here (the boot-time blocking
- * window is acceptable for a self-hosted gateway; consistency with the sibling index migrations
- * outweighs it).
+ * CREATE INDEX over a large table can run long. Boot and CLI migrations run on a pool without the
+ * runtime statement_timeout (pg-boot-migrations.ts); lifting it for THIS transaction only guards
+ * against a role- or database-level default cancelling the build (SET LOCAL auto-reverts at COMMIT;
+ * SQLite rejects it syntactically, hence the guard), the same discipline AddWebhooksSessionIdIndex
+ * and AddMessagesWaMessageIdUnique already use. `CONCURRENTLY` would avoid the SHARE lock (writes to
+ * messages wait for the build, reads do not) but cannot run inside a transaction, so it is
+ * deliberately NOT used here (the boot-time blocking window is acceptable for a self-hosted gateway;
+ * consistency with the sibling index migrations outweighs it).
*/
export class AddMessagesCreatedAtIndex1785123853000 implements MigrationInterface {
name = 'AddMessagesCreatedAtIndex1785123853000';
diff --git a/src/database/migrations/1786700000000-AddMessagesSessionChatCreatedAtIndex.ts b/src/database/migrations/1786700000000-AddMessagesSessionChatCreatedAtIndex.ts
index 23af2dd74..c59cad9f4 100644
--- a/src/database/migrations/1786700000000-AddMessagesSessionChatCreatedAtIndex.ts
+++ b/src/database/migrations/1786700000000-AddMessagesSessionChatCreatedAtIndex.ts
@@ -19,8 +19,9 @@ export class AddMessagesSessionChatCreatedAtIndex1786700000000 implements Migrat
name = 'AddMessagesSessionChatCreatedAtIndex1786700000000';
public async up(queryRunner: QueryRunner): Promise<void> {
- // The data pool boots with a runtime statement_timeout (default 30s), which a build over a large
- // messages table can outlast. Lift it for this transaction only, like AddMessageMediaPathIndex.
+ // Boot and CLI migrations run on a pool without the runtime statement_timeout (pg-boot-migrations.ts);
+ // this guards against a role- or database-level default cancelling a long build. Lifted for this
+ // transaction only, like AddMessageMediaPathIndex.
if (queryRunner.dataSource.options.type === 'postgres') {
await queryRunner.query('SET LOCAL statement_timeout = 0');
}