From 037b635d88a3cce5ea5af011034e4f0a710c0274 Mon Sep 17 00:00:00 2001 From: Pooya Raki Date: Thu, 7 Nov 2024 18:02:05 +0100 Subject: [PATCH] Add a new migration to clean up notification tables before creating new tables --- .../1726452966034-notification_cleanup.ts | 35 +++++++++++++++++++ .../1727451367471-notifications_enum.ts | 2 +- .../1727701600427-update_timestamp_trigger.ts | 2 +- ...01873513-notification_update_updated_at.ts | 2 +- 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 migrations/1726452966034-notification_cleanup.ts diff --git a/migrations/1726452966034-notification_cleanup.ts b/migrations/1726452966034-notification_cleanup.ts new file mode 100644 index 0000000000..7a9183b7b5 --- /dev/null +++ b/migrations/1726452966034-notification_cleanup.ts @@ -0,0 +1,35 @@ +import type { MigrationInterface, QueryRunner } from 'typeorm'; + +export class NotificationCleanup1726452966034 implements MigrationInterface { + name = 'NotificationCleanup1726452966034'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `DROP TRIGGER IF EXISTS "update_push_notification_devices_updated_at" ON "push_notification_devices"`, + ); + await queryRunner.query( + `DROP TRIGGER IF EXISTS "update_notification_subscriptions_updated_at" ON "notification_subscriptions"`, + ); + await queryRunner.query( + `DROP TYPE IF EXISTS "notification_types_name_enum" CASCADE`, + ); + await queryRunner.query( + `DROP TYPE IF EXISTS "push_notification_devices_device_type_enum" CASCADE`, + ); + await queryRunner.query(`DROP FUNCTION IF EXISTS update_updated_at()`); + await queryRunner.query( + `DROP TABLE IF EXISTS "push_notification_devices" CASCADE`, + ); + await queryRunner.query( + `DROP TABLE IF EXISTS "notification_subscriptions" CASCADE`, + ); + await queryRunner.query( + `DROP TABLE IF EXISTS "notification_subscription_notification_types" CASCADE`, + ); + await queryRunner.query( + `DROP TABLE IF EXISTS "notification_types" CASCADE`, + ); + } + + public async down(): Promise {} +} diff --git a/migrations/1727451367471-notifications_enum.ts b/migrations/1727451367471-notifications_enum.ts index 6510d85075..be4487d805 100644 --- a/migrations/1727451367471-notifications_enum.ts +++ b/migrations/1727451367471-notifications_enum.ts @@ -1,4 +1,4 @@ -import { MigrationInterface, QueryRunner } from 'typeorm'; +import type { MigrationInterface, QueryRunner } from 'typeorm'; export class NotificationsEnum1727451367471 implements MigrationInterface { name = 'NotificationsEnum1727451367471'; diff --git a/migrations/1727701600427-update_timestamp_trigger.ts b/migrations/1727701600427-update_timestamp_trigger.ts index d1f7f152e8..d8a7ae5b7a 100644 --- a/migrations/1727701600427-update_timestamp_trigger.ts +++ b/migrations/1727701600427-update_timestamp_trigger.ts @@ -1,4 +1,4 @@ -import { MigrationInterface, QueryRunner } from 'typeorm'; +import type { MigrationInterface, QueryRunner } from 'typeorm'; export class UpdateTimestampTrigger1727701600427 implements MigrationInterface { name = 'UpdateTimestampTrigger1727701600427'; diff --git a/migrations/1727701873513-notification_update_updated_at.ts b/migrations/1727701873513-notification_update_updated_at.ts index debdce42b1..53956e482b 100644 --- a/migrations/1727701873513-notification_update_updated_at.ts +++ b/migrations/1727701873513-notification_update_updated_at.ts @@ -1,4 +1,4 @@ -import { MigrationInterface, QueryRunner } from 'typeorm'; +import type { MigrationInterface, QueryRunner } from 'typeorm'; export class NotificationUpdateUpdatedAt1727701873513 implements MigrationInterface