Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

feat(status): add the status_updates TTL store entity and migration

Yudhi Armyndharis3c760282148a
diff --git a/src/app.module.ts b/src/app.module.ts
index f89ae44b0..7045abbf0 100644
--- a/src/app.module.ts
+++ b/src/app.module.ts
@@ -147,6 +147,7 @@ if (dashboardServingEnabled && dashboardBuildPresent) {
__dirname + '/modules/template/**/*.entity{.ts,.js}',
__dirname + '/engine/**/*.entity{.ts,.js}',
__dirname + '/modules/integration/**/*.entity{.ts,.js}',
+ __dirname + '/modules/status-store/**/*.entity{.ts,.js}',
],
migrations: [__dirname + '/database/migrations/*{.ts,.js}'],
logging: configService.get<boolean>('dataDatabase.logging', false),
diff --git a/src/database/data-source.ts b/src/database/data-source.ts
index 10ff15171..b4ce9c7ba 100644
--- a/src/database/data-source.ts
+++ b/src/database/data-source.ts
@@ -10,7 +10,7 @@ const dbType = process.env.DATABASE_TYPE || 'sqlite';
const sourceGlob = (...segments: string[]): string => path.join(__dirname, ...segments).replace(/\\/g, '/');
-// Scoped to the DATA-owned modules only (session/webhook/message/template/engine/integration), mirroring
+// Scoped to the DATA-owned modules only (session/webhook/message/template/engine/integration/status-store), mirroring
// the runtime data connection (app.module.ts). A broad '**' glob would also sweep in the main-owned
// auth/audit entities and pollute `migration:generate` against the data DB with their DDL.
const dataEntities = [
@@ -20,6 +20,7 @@ const dataEntities = [
sourceGlob('..', 'modules', 'template', '**', '*.entity{.ts,.js}'),
sourceGlob('..', 'engine', '**', '*.entity{.ts,.js}'),
sourceGlob('..', 'modules', 'integration', '**', '*.entity{.ts,.js}'),
+ sourceGlob('..', 'modules', 'status-store', '**', '*.entity{.ts,.js}'),
];
const dataMigrations = [sourceGlob('migrations', '*{.ts,.js}')];
diff --git a/src/database/migrations/1784822470680-CreateStatusUpdates.ts b/src/database/migrations/1784822470680-CreateStatusUpdates.ts
new file mode 100644
index 000000000..92c991100
--- /dev/null
+++ b/src/database/migrations/1784822470680-CreateStatusUpdates.ts
@@ -0,0 +1,46 @@
+import { MigrationInterface, QueryRunner } from 'typeorm';
+
+/**
+ * Creates the `status_updates` TTL store: WhatsApp Status/Story posts captured by the engine, kept
+ * around only until `expiresAt` (WhatsApp's own 24h TTL) for the Status API to serve.
+ *
+ * Hand-authored (not `migration:generate`) because the dev SQLite DB in this worktree already carries
+ * pre-existing schema drift on unrelated tables (webhooks/sessions/message_batches/
+ * baileys_stored_messages/templates/lid_mappings) — confirmed by running a dry-run generate WITHOUT
+ * this entity registered, which reproduced the identical multi-table rebuild cascade. Hand-authoring
+ * keeps this migration scoped to `status_updates` only, matching the repo's convention for recent
+ * additions (e.g. `AddIntegrationFabric`, `AddWebhooksSessionIdIndex`). Idempotent + cross-dialect.
+ */
+export class CreateStatusUpdates1784822470680 implements MigrationInterface {
+ name = 'CreateStatusUpdates1784822470680';
+
+ public async up(queryRunner: QueryRunner): Promise<void> {
+ if (await queryRunner.hasTable('status_updates')) return;
+
+ const isPostgres = queryRunner.dataSource.options.type === 'postgres';
+ const boolFalse = isPostgres ? 'false' : '0';
+
+ await queryRunner.query(
+ `CREATE TABLE "status_updates" (` +
+ `"id" varchar PRIMARY KEY NOT NULL, "sessionId" varchar NOT NULL, "contactJid" varchar NOT NULL, ` +
+ `"contactName" varchar, "contactPushName" varchar, "waStatusId" varchar NOT NULL, "type" varchar NOT NULL, ` +
+ `"caption" text, "mediaPath" varchar, "mediaMimetype" varchar, ` +
+ `"mediaOmitted" boolean NOT NULL DEFAULT ${boolFalse}, "omitReason" varchar, "backgroundColor" varchar, ` +
+ `"font" integer, "postedAt" bigint NOT NULL, "expiresAt" bigint NOT NULL)`,
+ );
+ await queryRunner.query(
+ `CREATE INDEX "IDX_status_updates_sessionId_contactJid" ON "status_updates" ("sessionId", "contactJid")`,
+ );
+ await queryRunner.query(
+ `CREATE UNIQUE INDEX "UQ_status_updates_sessionId_waStatusId" ON "status_updates" ("sessionId", "waStatusId")`,
+ );
+ await queryRunner.query(`CREATE INDEX "IDX_status_updates_expiresAt" ON "status_updates" ("expiresAt")`);
+ }
+
+ public async down(queryRunner: QueryRunner): Promise<void> {
+ await queryRunner.query(`DROP INDEX IF EXISTS "IDX_status_updates_expiresAt"`);
+ await queryRunner.query(`DROP INDEX IF EXISTS "UQ_status_updates_sessionId_waStatusId"`);
+ await queryRunner.query(`DROP INDEX IF EXISTS "IDX_status_updates_sessionId_contactJid"`);
+ await queryRunner.query(`DROP TABLE IF EXISTS "status_updates"`);
+ }
+}
diff --git a/src/modules/status-store/entities/status-update.entity.ts b/src/modules/status-store/entities/status-update.entity.ts
new file mode 100644
index 000000000..c1161386e
--- /dev/null
+++ b/src/modules/status-store/entities/status-update.entity.ts
@@ -0,0 +1,60 @@
+import { Column, Entity, Index, PrimaryGeneratedColumn } from 'typeorm';
+import { bigintToNumberTransformer } from '../../message/entities/message.entity';
+
+@Entity('status_updates')
+@Index(['sessionId', 'contactJid'])
+@Index(['sessionId', 'waStatusId'], { unique: true })
+export class StatusUpdate {
+ @PrimaryGeneratedColumn('uuid')
+ id!: string;
+
+ @Column()
+ sessionId!: string;
+
+ /** Neutral @c.us / @lid JID of the contact who posted. */
+ @Column()
+ contactJid!: string;
+
+ @Column({ nullable: true })
+ contactName?: string;
+
+ @Column({ nullable: true })
+ contactPushName?: string;
+
+ /** Engine status id, e.g. false_status@broadcast_<hash>. */
+ @Column()
+ waStatusId!: string;
+
+ @Column()
+ type!: 'text' | 'image' | 'video';
+
+ @Column({ type: 'text', nullable: true })
+ caption?: string;
+
+ /** Relative path under the media store; null for text or omitted media. */
+ @Column({ nullable: true })
+ mediaPath?: string;
+
+ @Column({ nullable: true })
+ mediaMimetype?: string;
+
+ @Column({ default: false })
+ mediaOmitted!: boolean;
+
+ /** 'over_cap' | 'engine_omitted' | 'write_failed' — null when media is present or type is text. */
+ @Column({ nullable: true })
+ omitReason?: string;
+
+ @Column({ nullable: true })
+ backgroundColor?: string;
+
+ @Column({ type: 'int', nullable: true })
+ font?: number;
+
+ @Column({ type: 'bigint', transformer: bigintToNumberTransformer })
+ postedAt!: number; // epoch ms
+
+ @Column({ type: 'bigint', transformer: bigintToNumberTransformer })
+ @Index()
+ expiresAt!: number; // epoch ms
+}