Spaces:
Runtime error
Runtime error
File size: 1,262 Bytes
46252cd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import { MigrationInterface, QueryRunner } from 'typeorm';
/**
* Adds `chatName` column to the `messages` table. This stores the human-readable name for the
* chat (contact pushName, group name, etc) at the time the message was received/sent, enabling
* stats endpoints to display readable names instead of raw JIDs.
*
* Hand-authored because `synchronize` is off for the `data` connection on PostgreSQL (and optional
* on SQLite via DATABASE_SYNCHRONIZE=false). Idempotent: checks for column existence first.
*/
export class AddMessageChatName1782000000000 implements MigrationInterface {
name = 'AddMessageChatName1782000000000';
public async up(queryRunner: QueryRunner): Promise<void> {
const table = await queryRunner.getTable('messages');
const col = table?.findColumnByName('chatName');
if (col) return; // already added by synchronize or a previous run
await queryRunner.query(`ALTER TABLE "messages" ADD COLUMN "chatName" varchar NULL`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
const table = await queryRunner.getTable('messages');
const col = table?.findColumnByName('chatName');
if (!col) return;
await queryRunner.query(`ALTER TABLE "messages" DROP COLUMN "chatName"`);
}
}
|