Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
docs(migrations): say why SET LOCAL statement_timeout stays
Yudhi Armyndharis4f088dd854c6
diff --git a/src/database/migrations/1781300000000-AddMessagesWaMessageIdUnique.ts b/src/database/migrations/1781300000000-AddMessagesWaMessageIdUnique.tsindex 196e5114c..85daae2f9 100644--- a/src/database/migrations/1781300000000-AddMessagesWaMessageIdUnique.ts+++ b/src/database/migrations/1781300000000-AddMessagesWaMessageIdUnique.ts@@ -15,10 +15,10 @@ export class AddMessagesWaMessageIdUnique1781300000000 implements MigrationInterpublic async up(queryRunner: QueryRunner): Promise<void> {if (queryRunner.dataSource.options.type === 'postgres') {- // The runtime 'data' pool carries a statement_timeout (app.module.ts) and migrations run on it at- // boot. Lift it for THIS transaction so the dedup DELETE / CREATE UNIQUE INDEX over the hot messages- // table is never aborted mid-flight. SET LOCAL is transaction-scoped (auto-reverts at COMMIT) and is- // a no-op everywhere else — SQLite rejects it syntactically, hence the guard.+ // Boot and CLI migrations run on a pool without the runtime statement_timeout (pg-boot-migrations.ts);+ // this guards the dedup DELETE / CREATE UNIQUE INDEX over the hot messages table against a role- or+ // database-level default aborting it mid-flight. SET LOCAL is transaction-scoped (auto-reverts at+ // COMMIT); SQLite rejects it syntactically, hence the guard.await queryRunner.query('SET LOCAL statement_timeout = 0');}if (!(await queryRunner.hasTable('messages'))) return;diff --git a/src/database/migrations/1782200000000-AddWebhooksSessionIdIndex.ts b/src/database/migrations/1782200000000-AddWebhooksSessionIdIndex.tsindex 8095491e9..9d98bd8f1 100644--- a/src/database/migrations/1782200000000-AddWebhooksSessionIdIndex.ts+++ b/src/database/migrations/1782200000000-AddWebhooksSessionIdIndex.ts@@ -13,9 +13,9 @@ export class AddWebhooksSessionIdIndex1782200000000 implements MigrationInterfacpublic async up(queryRunner: QueryRunner): Promise<void> {if (queryRunner.dataSource.options.type === 'postgres') {- // Lift the runtime pool's statement_timeout (app.module.ts) for THIS transaction so a CREATE INDEX- // over a large webhooks table at boot is never aborted. SET LOCAL auto-reverts at COMMIT; SQLite- // rejects it syntactically, hence the guard.+ // Boot and CLI migrations run on a pool without the runtime statement_timeout (pg-boot-migrations.ts);+ // this guards a CREATE INDEX over a large webhooks table against a role- or database-level default.+ // SET LOCAL auto-reverts at COMMIT; SQLite rejects it syntactically, hence the guard.await queryRunner.query('SET LOCAL statement_timeout = 0');}if (!(await queryRunner.hasTable('webhooks'))) return;diff --git a/src/database/migrations/1782400000000-AddMessagesFts.ts b/src/database/migrations/1782400000000-AddMessagesFts.tsindex 3b068a331..8efa7899d 100644--- a/src/database/migrations/1782400000000-AddMessagesFts.ts+++ b/src/database/migrations/1782400000000-AddMessagesFts.ts@@ -16,10 +16,10 @@ export class AddMessagesFts1782400000000 implements MigrationInterface {async up(qr: QueryRunner): Promise<void> {const isPostgres = qr.dataSource.options.type === 'postgres';if (isPostgres) {- // Lift the runtime statement_timeout (30000ms on the data pool — see app.module.ts) for this- // migration transaction: the STORED generated column is a full-table rewrite, and the GIN index- // build that follows is the heaviest boot migration. Without this, a large `messages` table can- // exceed 30s and be aborted → boot crash. SET LOCAL is transaction-scoped (auto-reverts) and is+ // Boot and CLI migrations run on a pool without the runtime statement_timeout+ // (pg-boot-migrations.ts). SET LOCAL guards this transaction against a role- or database-level+ // default: the STORED generated column is a full-table rewrite, and the GIN index build that+ // follows is the heaviest boot migration. SET LOCAL is transaction-scoped (auto-reverts) and is// guarded by the dialect since SQLite rejects it syntactically. Mirrors 1781100000000 /// 1781300000000 / 1782200000000.await qr.query('SET LOCAL statement_timeout = 0');diff --git a/src/database/migrations/1786100000000-AddMessageMediaPathIndex.ts b/src/database/migrations/1786100000000-AddMessageMediaPathIndex.tsindex 0d8ad623c..6c97edac4 100644--- a/src/database/migrations/1786100000000-AddMessageMediaPathIndex.ts+++ b/src/database/migrations/1786100000000-AddMessageMediaPathIndex.ts@@ -16,11 +16,9 @@ export class AddMessageMediaPathIndex1786100000000 implements MigrationInterfacename = 'AddMessageMediaPathIndex1786100000000';public async up(queryRunner: QueryRunner): Promise<void> {- // The data pool boots with a runtime statement_timeout (default 30s). On an upgrade where this- // is the only pending migration, MigrationExecutor wraps it in its OWN transaction, so no- // earlier migration's SET LOCAL is in effect and a CREATE INDEX over a large messages table is- // cancelled at the timeout, aborting the ledger-advancing transaction and crash-looping the- // boot retries. Lift it for this transaction only, exactly like AddMessagesCreatedAtIndex.+ // Boot and CLI migrations run on a pool without the runtime statement_timeout (pg-boot-migrations.ts),+ // and MigrationExecutor wraps a lone pending migration in its own transaction, so lift any role- or+ // database-level default for this transaction only, exactly like AddMessagesCreatedAtIndex.if (queryRunner.dataSource.options.type === 'postgres') {await queryRunner.query('SET LOCAL statement_timeout = 0');}diff --git a/src/database/migrations/1786300000000-AddWebhookDeliveryFailureLookupIndex.ts b/src/database/migrations/1786300000000-AddWebhookDeliveryFailureLookupIndex.tsindex d6078850e..912cd158a 100644--- a/src/database/migrations/1786300000000-AddWebhookDeliveryFailureLookupIndex.ts+++ b/src/database/migrations/1786300000000-AddWebhookDeliveryFailureLookupIndex.ts@@ -15,9 +15,9 @@ export class AddWebhookDeliveryFailureLookupIndex1786300000000 implements Migratname = 'AddWebhookDeliveryFailureLookupIndex1786300000000';public async up(queryRunner: QueryRunner): Promise<void> {- // The data pool boots with a runtime statement_timeout (default 30s), and MigrationExecutor- // wraps a lone pending migration in its own transaction, so no earlier SET LOCAL is in effect.- // Lift it for this transaction only, exactly like AddMessageMediaPathIndex.+ // Boot and CLI migrations run on a pool without the runtime statement_timeout (pg-boot-migrations.ts),+ // and MigrationExecutor wraps a lone pending migration in its own transaction, so lift any role- or+ // database-level default for this transaction only, exactly like AddMessageMediaPathIndex.if (queryRunner.dataSource.options.type === 'postgres') {await queryRunner.query('SET LOCAL statement_timeout = 0');}diff --git a/src/database/migrations/1786800000000-AddBaileysStoredMessagesSessionCreatedIdIndex.ts b/src/database/migrations/1786800000000-AddBaileysStoredMessagesSessionCreatedIdIndex.tsindex 525dc0d53..3959d827c 100644--- a/src/database/migrations/1786800000000-AddBaileysStoredMessagesSessionCreatedIdIndex.ts+++ b/src/database/migrations/1786800000000-AddBaileysStoredMessagesSessionCreatedIdIndex.ts@@ -17,7 +17,9 @@ export class AddBaileysStoredMessagesSessionCreatedIdIndex1786800000000 implemenname = 'AddBaileysStoredMessagesSessionCreatedIdIndex1786800000000';public async up(queryRunner: QueryRunner): Promise<void> {- // Lift the runtime statement_timeout for this transaction only, as AddMessageMediaPathIndex does.+ // 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, as+ // AddMessageMediaPathIndex does.if (queryRunner.dataSource.options.type === 'postgres') {await queryRunner.query('SET LOCAL statement_timeout = 0');}