43 lines
1.6 KiB
TypeScript
43 lines
1.6 KiB
TypeScript
import { MigrationInterface, QueryRunner } from 'typeorm';
|
|
import { SmsScenarioKey } from '../../sms-settings/enums/sms-scenario-key.enum';
|
|
import { NotificationScenarioKey } from '../../notifications/enums/notification-scenario-key.enum';
|
|
|
|
const NEW_SMS_KEYS = [
|
|
SmsScenarioKey.DEPOSIT_PAYMENT_REQUEST,
|
|
SmsScenarioKey.DEPOSIT_RECEIPT_SUBMITTED,
|
|
SmsScenarioKey.DEPOSIT_APPROVED,
|
|
SmsScenarioKey.DEPOSIT_REJECTED,
|
|
];
|
|
|
|
const NEW_NOTIFICATION_KEYS = [NotificationScenarioKey.DEPOSIT_RECEIPT_SUBMITTED];
|
|
|
|
/**
|
|
* Only adds the new enum values. Postgres forbids using a newly added enum
|
|
* value in the same transaction it was created in, so seeding the actual
|
|
* scenario rows is handled by the follow-up `SeedDepositScenarios` migration.
|
|
* `transaction = false` commits ADD VALUE immediately (required by Postgres).
|
|
*/
|
|
export class AddDepositScenarios1722000000000 implements MigrationInterface {
|
|
name = 'AddDepositScenarios1722000000000';
|
|
transaction = false;
|
|
|
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
for (const key of NEW_SMS_KEYS) {
|
|
await queryRunner.query(
|
|
`ALTER TYPE "sms_scenario_key_enum" ADD VALUE IF NOT EXISTS '${key}'`,
|
|
);
|
|
}
|
|
|
|
for (const key of NEW_NOTIFICATION_KEYS) {
|
|
await queryRunner.query(
|
|
`ALTER TYPE "notification_scenario_key_enum" ADD VALUE IF NOT EXISTS '${key}'`,
|
|
);
|
|
}
|
|
}
|
|
|
|
public async down(): Promise<void> {
|
|
// Enum values cannot be dropped without recreating the type; left as-is on downgrade.
|
|
// Seeded rows (if any) are removed by SeedDepositScenarios's down().
|
|
}
|
|
}
|