import { MigrationInterface, QueryRunner } from "typeorm";

export class Migrations1766989226931 implements MigrationInterface {
    name = 'Migrations1766989226931'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`CREATE TABLE "category_translations" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "language_code" character varying(10) NOT NULL DEFAULT 'en', "title" character varying NOT NULL DEFAULT '', "slug" character varying NOT NULL DEFAULT '', "description" text, "tags" text, "created_at" TIMESTAMP(0) NOT NULL DEFAULT now(), "updated_at" TIMESTAMP(0) NOT NULL DEFAULT now(), "deleted_at" TIMESTAMP(0), "category_id" uuid, CONSTRAINT "PK_9dff018a4a26a924c60d3e86432" PRIMARY KEY ("id"))`);
        await queryRunner.query(`CREATE INDEX "IDX_e4e2ac4768cfa80ec4eb0ab44b" ON "category_translations" ("language_code") `);
        await queryRunner.query(`CREATE INDEX "IDX_17a25657d99871c24184b6011b" ON "category_translations" ("title") `);
        await queryRunner.query(`CREATE INDEX "IDX_1751db555e149ae23a900708fc" ON "category_translations" ("slug") `);
        await queryRunner.query(`ALTER TABLE "category_translations" ADD CONSTRAINT "FK_87902f79e775e1c1b0082201d7e" FOREIGN KEY ("category_id") REFERENCES "categories"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE "category_translations" DROP CONSTRAINT "FK_87902f79e775e1c1b0082201d7e"`);
        await queryRunner.query(`DROP INDEX "public"."IDX_1751db555e149ae23a900708fc"`);
        await queryRunner.query(`DROP INDEX "public"."IDX_17a25657d99871c24184b6011b"`);
        await queryRunner.query(`DROP INDEX "public"."IDX_e4e2ac4768cfa80ec4eb0ab44b"`);
        await queryRunner.query(`DROP TABLE "category_translations"`);
    }

}
