import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddPlatformSettings1775000000000 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      CREATE TABLE IF NOT EXISTS "platform_settings" (
        "id" varchar(50) NOT NULL DEFAULT 'global',
        "build_link_expiry_days" int NOT NULL DEFAULT 0,
        "ai_release_notes_enabled" boolean NOT NULL DEFAULT true,
        "updated_at" TIMESTAMP NOT NULL DEFAULT now(),
        CONSTRAINT "PK_platform_settings" PRIMARY KEY ("id")
      )
    `);

    await queryRunner.query(`
      INSERT INTO "platform_settings" ("id", "build_link_expiry_days", "ai_release_notes_enabled")
      VALUES ('global', 0, true)
      ON CONFLICT ("id") DO NOTHING
    `);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`DROP TABLE IF EXISTS "platform_settings"`);
  }
}
