Files
zod-backend/src/db/migrations/1749633935436-create-card-entity.ts
Abdalhamid Alhamad 2770cf8774 fix:fix card migration
2025-07-07 12:06:01 +03:00

41 lines
2.0 KiB
TypeScript

import { MigrationInterface, QueryRunner } from 'typeorm';
export class CreateCardEntity1749633935436 implements MigrationInterface {
name = 'CreateCardEntity1749633935436';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "cards"
("id" uuid NOT NULL DEFAULT uuid_generate_v4(),
"card_reference" character varying NOT NULL,
"first_six_digits" character varying(6) NOT NULL,
"last_four_digits" character varying(4) NOT NULL,
"expiry" character varying NOT NULL,
"customer_type" character varying NOT NULL,
"color" character varying NOT NULL DEFAULT 'BLUE',
"status" character varying NOT NULL DEFAULT 'PENDING',
"scheme" character varying NOT NULL DEFAULT 'VISA',
"issuer" character varying NOT NULL,
"customer_id" uuid NOT NULL,
"parent_id" uuid,
"created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
"updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
CONSTRAINT "PK_9451069b6f1199730791a7f4ae4" PRIMARY KEY ("id"))`,
);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_6fb82820c0b1b7ec32a8dbf911" ON "cards" ("card_reference") `);
await queryRunner.query(
`ALTER TABLE "cards" ADD CONSTRAINT "FK_d46837f6ab27271d8125517d0b6" FOREIGN KEY ("parent_id") REFERENCES "customers"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "cards" ADD CONSTRAINT "FK_f5aa0baf4ff1b397b3f946a443e" FOREIGN KEY ("customer_id") REFERENCES "customers"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "cards" DROP CONSTRAINT "FK_f5aa0baf4ff1b397b3f946a443e"`);
await queryRunner.query(`ALTER TABLE "cards" DROP CONSTRAINT "FK_d46837f6ab27271d8125517d0b6"`);
await queryRunner.query(`DROP INDEX "public"."IDX_6fb82820c0b1b7ec32a8dbf911"`);
await queryRunner.query(`DROP TABLE "cards"`);
}
}