import { MigrationInterface, QueryRunner } from 'typeorm'; export class InitialSchema1700000000000 implements MigrationInterface { name = 'InitialSchema1700000000000'; public async up(queryRunner: QueryRunner): Promise { if (queryRunner.connection.options.type === 'postgres') { await queryRunner.query('CREATE EXTENSION IF NOT EXISTS "uuid-ossp"'); } // Capture the entity-to-database delta once, then execute it as this // initial migration. This keeps the initial schema aligned with all // registered entities while production still runs with synchronize=false. const schemaBuilder = ( queryRunner.connection.driver as unknown as { createSchemaBuilder: () => { log: () => Promise<{ upQueries: Array<{ query: string; parameters?: unknown[] }>; }>; }; } ).createSchemaBuilder(); const schema = await schemaBuilder.log(); for (const query of schema.upQueries) { await queryRunner.query(query.query, query.parameters); } } public async down(queryRunner: QueryRunner): Promise { const tables = [ 'tg_webhook_deliveries', 'tg_webhook_subscriptions', 'tg_rate_limit_events', 'tg_raw_updates', 'tg_audit_logs', 'tg_files', 'tg_send_jobs', 'tg_messages', 'tg_groups', 'tg_contacts', 'tg_users', 'tg_chats', 'tg_account_proxy_bindings', 'tg_proxies', 'tg_accounts', 'users', 'tenants', ]; for (const table of tables) { await queryRunner.dropTable(table, true, true, true); } } }