From 2ba959b3ae88150d5ab64b6501275540783326ca Mon Sep 17 00:00:00 2001 From: Mahdi Date: Mon, 29 Jun 2026 17:11:39 +0330 Subject: [PATCH] awaiting_payment set --- ...6900000-AddBookingPaymentAndAutoApprove.ts | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/database/migrations/1789046900000-AddBookingPaymentAndAutoApprove.ts diff --git a/src/database/migrations/1789046900000-AddBookingPaymentAndAutoApprove.ts b/src/database/migrations/1789046900000-AddBookingPaymentAndAutoApprove.ts new file mode 100644 index 0000000..60522dc --- /dev/null +++ b/src/database/migrations/1789046900000-AddBookingPaymentAndAutoApprove.ts @@ -0,0 +1,73 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class AddBookingPaymentAndAutoApprove1789046900000 + implements MigrationInterface +{ + name = 'AddBookingPaymentAndAutoApprove1789046900000'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + ALTER TABLE "businesses" + ADD COLUMN IF NOT EXISTS "autoApproveBookings" boolean NOT NULL DEFAULT false + `); + + await queryRunner.query(` + ALTER TABLE "bookings" + ADD COLUMN IF NOT EXISTS "paymentToken" varchar(64) + `); + + await queryRunner.query(` + ALTER TABLE "bookings" + ADD COLUMN IF NOT EXISTS "paymentAmount" numeric(12,0) + `); + + await queryRunner.query(` + ALTER TABLE "bookings" + ADD COLUMN IF NOT EXISTS "paymentAuthority" varchar(64) + `); + + await queryRunner.query(` + DO $$ + DECLARE + enum_type regtype; + BEGIN + SELECT a.atttypid::regtype INTO enum_type + FROM pg_attribute a + JOIN pg_class c ON a.attrelid = c.oid + JOIN pg_namespace n ON c.relnamespace = n.oid + WHERE c.relname = 'bookings' + AND n.nspname = current_schema() + AND a.attname = 'status' + AND NOT a.attisdropped; + + IF enum_type IS NULL THEN + RETURN; + END IF; + + IF NOT EXISTS ( + SELECT 1 + FROM pg_enum e + WHERE e.enumtypid = enum_type::oid + AND e.enumlabel = 'awaiting_payment' + ) THEN + EXECUTE format('ALTER TYPE %s ADD VALUE %L', enum_type, 'awaiting_payment'); + END IF; + END $$; + `); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + ALTER TABLE "bookings" DROP COLUMN IF EXISTS "paymentAuthority" + `); + await queryRunner.query(` + ALTER TABLE "bookings" DROP COLUMN IF EXISTS "paymentAmount" + `); + await queryRunner.query(` + ALTER TABLE "bookings" DROP COLUMN IF EXISTS "paymentToken" + `); + await queryRunner.query(` + ALTER TABLE "businesses" DROP COLUMN IF EXISTS "autoApproveBookings" + `); + } +}