sms-setting and campain
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
import {
|
||||
MigrationInterface,
|
||||
QueryRunner,
|
||||
Table,
|
||||
TableForeignKey,
|
||||
TableIndex,
|
||||
} from 'typeorm';
|
||||
import { SMS_SCENARIOS } from '../../sms-settings/constants/sms-scenarios.constants';
|
||||
|
||||
export class AddSmsScenarioSettings1721200000000 implements MigrationInterface {
|
||||
name = 'AddSmsScenarioSettings1721200000000';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
CREATE TYPE "sms_scenario_key_enum" AS ENUM (
|
||||
'otp_login',
|
||||
'reserve_created',
|
||||
'reserve_reminder',
|
||||
'reserve_confirmed',
|
||||
'reserve_cancelled'
|
||||
)
|
||||
`);
|
||||
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: 'sms_scenario_settings',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
type: 'uuid',
|
||||
isPrimary: true,
|
||||
generationStrategy: 'uuid',
|
||||
default: 'gen_random_uuid()',
|
||||
},
|
||||
{
|
||||
name: 'key',
|
||||
type: 'sms_scenario_key_enum',
|
||||
isUnique: true,
|
||||
},
|
||||
{ name: 'body', type: 'text', isNullable: true },
|
||||
{ name: 'templateId', type: 'uuid', isNullable: true },
|
||||
{ name: 'isActive', type: 'boolean', default: true },
|
||||
{ name: 'createdAt', type: 'timestamp', default: 'now()' },
|
||||
{ name: 'updatedAt', type: 'timestamp', default: 'now()' },
|
||||
],
|
||||
}),
|
||||
true,
|
||||
);
|
||||
|
||||
await queryRunner.createIndex(
|
||||
'sms_scenario_settings',
|
||||
new TableIndex({
|
||||
name: 'IDX_sms_scenario_settings_key',
|
||||
columnNames: ['key'],
|
||||
isUnique: true,
|
||||
}),
|
||||
);
|
||||
|
||||
await queryRunner.createForeignKey(
|
||||
'sms_scenario_settings',
|
||||
new TableForeignKey({
|
||||
name: 'FK_sms_scenario_settings_templateId',
|
||||
columnNames: ['templateId'],
|
||||
referencedTableName: 'sms_templates',
|
||||
referencedColumnNames: ['id'],
|
||||
onDelete: 'SET NULL',
|
||||
}),
|
||||
);
|
||||
|
||||
for (const scenario of SMS_SCENARIOS) {
|
||||
await queryRunner.query(
|
||||
`
|
||||
INSERT INTO sms_scenario_settings (key, body, "isActive")
|
||||
VALUES ($1, $2, true)
|
||||
`,
|
||||
[scenario.key, scenario.defaultBody],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.dropTable('sms_scenario_settings', true);
|
||||
await queryRunner.query('DROP TYPE "sms_scenario_key_enum"');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user