import { MigrationInterface, QueryRunner } from 'typeorm'

export class InitialMigration1695206513453 implements MigrationInterface {
	name = 'InitialMigration1695206513453'

	public async up(queryRunner: QueryRunner): Promise<void> {
		await queryRunner.query(
			`CREATE TABLE "category" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "deletedAt" TIMESTAMP, "name" character varying(60) NOT NULL, "sortOrder" integer NOT NULL, "isArchived" boolean NOT NULL DEFAULT false, "parentCategoryId" uuid, CONSTRAINT "PK_9c4e4a89e3674fc9f382d733f03" PRIMARY KEY ("id"))`,
		)
		await queryRunner.query(
			`ALTER TABLE "category" ADD CONSTRAINT "FK_9e5435ba76dbc1f1a0705d4db43" FOREIGN KEY ("parentCategoryId") REFERENCES "category"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
		)
	}

	public async down(queryRunner: QueryRunner): Promise<void> {
		await queryRunner.query(`ALTER TABLE "category" DROP CONSTRAINT "FK_9e5435ba76dbc1f1a0705d4db43"`)
		await queryRunner.query(`DROP TABLE "category"`)
	}
}
