|
| 1 | +import { MigrationInterface, QueryRunner } from "typeorm"; |
| 2 | + |
| 3 | +export class CreateWebhookSubscriptionsTable1712000000000 |
| 4 | + implements MigrationInterface |
| 5 | +{ |
| 6 | + name = "CreateWebhookSubscriptionsTable1712000000000"; |
| 7 | + |
| 8 | + public async up(queryRunner: QueryRunner): Promise<void> { |
| 9 | + await queryRunner.query(` |
| 10 | + CREATE TABLE "webhook_subscriptions" ( |
| 11 | + "id" uuid NOT NULL DEFAULT gen_random_uuid(), |
| 12 | + "user_id" uuid NOT NULL, |
| 13 | + "url" character varying(255) NOT NULL, |
| 14 | + "secret" character varying(64) NOT NULL, |
| 15 | + "event_types" jsonb NOT NULL, |
| 16 | + "active" boolean NOT NULL DEFAULT true, |
| 17 | + "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), |
| 18 | + "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), |
| 19 | + CONSTRAINT "PK_webhook_subscriptions" PRIMARY KEY ("id") |
| 20 | + ); |
| 21 | + `); |
| 22 | + |
| 23 | + await queryRunner.query(` |
| 24 | + CREATE INDEX "idx_webhook_subscriptions_user_id" |
| 25 | + ON "webhook_subscriptions" ("user_id"); |
| 26 | + `); |
| 27 | + |
| 28 | + await queryRunner.query(` |
| 29 | + ALTER TABLE "webhook_subscriptions" |
| 30 | + ADD CONSTRAINT "FK_webhook_subscriptions_user" |
| 31 | + FOREIGN KEY ("user_id") REFERENCES "users"("id") |
| 32 | + ON DELETE CASCADE; |
| 33 | + `); |
| 34 | + } |
| 35 | + |
| 36 | + public async down(queryRunner: QueryRunner): Promise<void> { |
| 37 | + await queryRunner.query(` |
| 38 | + ALTER TABLE "webhook_subscriptions" |
| 39 | + DROP CONSTRAINT "FK_webhook_subscriptions_user"; |
| 40 | + `); |
| 41 | + |
| 42 | + await queryRunner.query(` |
| 43 | + DROP INDEX "public"."idx_webhook_subscriptions_user_id"; |
| 44 | + `); |
| 45 | + |
| 46 | + await queryRunner.query(`DROP TABLE "webhook_subscriptions"`); |
| 47 | + } |
| 48 | +} |
0 commit comments