Fix SMS/notification migrations seeding keys before enum values exist

This commit is contained in:
2026-07-10 15:03:38 +03:30
parent 3e79cb69b3
commit 7a5d2bb137
2 changed files with 35 additions and 2 deletions
@@ -6,6 +6,16 @@ import {
TableIndex,
} from 'typeorm';
import { SMS_SCENARIOS } from '../../sms-settings/constants/sms-scenarios.constants';
import { SmsScenarioKey } from '../../sms-settings/enums/sms-scenario-key.enum';
/** Keys that exist on the enum created in this migration (later keys are seeded elsewhere). */
const INITIAL_SCENARIO_KEYS = [
SmsScenarioKey.OTP_LOGIN,
SmsScenarioKey.RESERVE_CREATED,
SmsScenarioKey.RESERVE_REMINDER,
SmsScenarioKey.RESERVE_CONFIRMED,
SmsScenarioKey.RESERVE_CANCELLED,
];
export class AddSmsScenarioSettings1721200000000 implements MigrationInterface {
name = 'AddSmsScenarioSettings1721200000000';
@@ -67,11 +77,17 @@ export class AddSmsScenarioSettings1721200000000 implements MigrationInterface {
}),
);
for (const scenario of SMS_SCENARIOS) {
for (const key of INITIAL_SCENARIO_KEYS) {
const scenario = SMS_SCENARIOS.find((item) => item.key === key);
if (!scenario) {
continue;
}
await queryRunner.query(
`
INSERT INTO sms_scenario_settings (key, body, "isActive")
VALUES ($1, $2, true)
ON CONFLICT (key) DO NOTHING
`,
[scenario.key, scenario.defaultBody],
);
@@ -6,6 +6,17 @@ import {
TableIndex,
} from 'typeorm';
import { NOTIFICATION_SCENARIOS } from '../../notifications/constants/notification-scenarios.constants';
import { NotificationScenarioKey } from '../../notifications/enums/notification-scenario-key.enum';
/** Keys that exist on the enum created in this migration (deposit key is seeded later). */
const INITIAL_NOTIFICATION_KEYS = [
NotificationScenarioKey.RESERVE_CREATED,
NotificationScenarioKey.RESERVE_CONFIRMED,
NotificationScenarioKey.RESERVE_CANCELLED,
NotificationScenarioKey.RESERVE_REMINDER_SENT,
NotificationScenarioKey.CAMPAIGN_SENT,
NotificationScenarioKey.CAMPAIGN_FAILED,
];
export class AddNotifications1721500000000 implements MigrationInterface {
name = 'AddNotifications1721500000000';
@@ -142,11 +153,17 @@ export class AddNotifications1721500000000 implements MigrationInterface {
}),
);
for (const scenario of NOTIFICATION_SCENARIOS) {
for (const key of INITIAL_NOTIFICATION_KEYS) {
const scenario = NOTIFICATION_SCENARIOS.find((item) => item.key === key);
if (!scenario) {
continue;
}
await queryRunner.query(
`
INSERT INTO notification_scenario_settings (key, title, body, "isActive")
VALUES ($1, $2, $3, true)
ON CONFLICT (key) DO NOTHING
`,
[scenario.key, scenario.defaultTitle, scenario.defaultBody],
);