awaiting_payment set
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddBookingPaymentAndAutoApprove1789046900000
|
||||
implements MigrationInterface
|
||||
{
|
||||
name = 'AddBookingPaymentAndAutoApprove1789046900000';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
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<void> {
|
||||
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"
|
||||
`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user