import { MigrationInterface, QueryRunner } from 'typeorm'; import { SYSTEM_CATEGORY_KEYS, SYSTEM_CATEGORY_META, DEFAULT_SETTINGS, SETTINGS_KEYS } from '../../config/env.schema'; import { v4 as uuid } from 'uuid'; export class SeedSystemData1700000000100 implements MigrationInterface { name = 'SeedSystemData1700000000100'; public async up(queryRunner: QueryRunner): Promise { for (const key of SYSTEM_CATEGORY_KEYS) { const meta = SYSTEM_CATEGORY_META[key]; const existing = await queryRunner.query(`SELECT id FROM "category" WHERE "system_key" = ?`, [key]); if (existing.length > 0) continue; await queryRunner.query( `INSERT INTO "category" ("id","system_key","name","abbreviation","description","icon_path") VALUES (?,?,?,?,?,?)`, [uuid(), key, meta.name, meta.abbreviation, meta.description, meta.iconPath], ); } for (const key of Object.values(SETTINGS_KEYS)) { const existing = await queryRunner.query(`SELECT "key" FROM "setting" WHERE "key" = ?`, [key]); if (existing.length > 0) continue; const value = DEFAULT_SETTINGS[key] ?? ''; await queryRunner.query(`INSERT INTO "setting" ("key","value") VALUES (?,?)`, [key, value]); } } public async down(queryRunner: QueryRunner): Promise { await queryRunner.query(`DELETE FROM "category" WHERE "system_key" IS NOT NULL;`); await queryRunner.query(`DELETE FROM "setting";`); } }