Skip to content

Commit

Permalink
refactor: create separate kaps seed migration file (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
Harish-osmosys authored May 29, 2024
1 parent b32415c commit d1c88c2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
11 changes: 1 addition & 10 deletions apps/api/src/database/migrations/1692870736646-seeddata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,6 @@ export class SeedData1692870736646 implements MigrationInterface {
],
);

await queryRunner.query(
`INSERT INTO notify_master_providers (name,provider_type,configuration) VALUES (?, ?, ?)`,
[
'SMS_KAPSYSTEM',
2,
'{"KAP_SMS_BASE_API_URL": {"lable": "KAP SMS BASE API URL","id": "KAP_SMS_BASE_API_URL","pattern": "^https?://[^(\\?\\s)]+$","type": "string"},"KAP_SMS_ACCOUNT_USERNAME": {"lable": "KAP SMS ACCOUNT USERNAME","id": "KAP_SMS_ACCOUNT_USERNAME","pattern": "^[a-zA-Z0-9_-]{3,30}$","type": "string"},"KAP_SMS_ACCOUNT_PASSWORD": {"lable": "KAP_SMS_ACCOUNT_PASSWORD","id": "KAP SMS ACCOUNT PASSWORD","pattern": "^[a-zA-Z0-9_-]{3,30}$","type": "string"},"KAP_SMS_FROM": {"lable": "KAP SMS FROM","id": "KAP_SMS_FROM","pattern": "^[a-zA-Z]{6}$","type": "string"}}',
],
);

// Add foreign key for channel_type -> master_id
// Adding this after seeding data in master_providers so FK constraint does not fail
await queryRunner.createForeignKey(
Expand All @@ -111,7 +102,7 @@ export class SeedData1692870736646 implements MigrationInterface {
await queryRunner.dropForeignKey('notify_notifications', 'channel_type');
await queryRunner.query(`
DELETE FROM notify_master_providers
WHERE id IN (1, 2, 3, 4, 5, 6, 7, 8);
WHERE id IN (1, 2, 3, 4, 5, 6, 7);
`);
await queryRunner.query(`
DELETE FROM notify_server_api_keys
Expand Down
23 changes: 23 additions & 0 deletions apps/api/src/database/migrations/1692870736647-kapsseeddata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class KapsSeedData1692870736647 implements MigrationInterface {
name = 'KapsSeedData1692870736647';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`INSERT INTO notify_master_providers (name,provider_type,configuration) VALUES (?, ?, ?)`,
[
'SMS_KAPSYSTEM',
2,
'{"KAP_SMS_BASE_API_URL": {"lable": "KAP SMS BASE API URL","id": "KAP_SMS_BASE_API_URL","pattern": "^https?://[^(\\?\\s)]+$","type": "string"},"KAP_SMS_ACCOUNT_USERNAME": {"lable": "KAP SMS ACCOUNT USERNAME","id": "KAP_SMS_ACCOUNT_USERNAME","pattern": "^[a-zA-Z0-9_-]{3,30}$","type": "string"},"KAP_SMS_ACCOUNT_PASSWORD": {"lable": "KAP_SMS_ACCOUNT_PASSWORD","id": "KAP SMS ACCOUNT PASSWORD","pattern": "^[a-zA-Z0-9_-]{3,30}$","type": "string"},"KAP_SMS_FROM": {"lable": "KAP SMS FROM","id": "KAP_SMS_FROM","pattern": "^[a-zA-Z]{6}$","type": "string"}}',
],
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
DELETE FROM notify_master_providers
WHERE master_id = 8;
`);
}
}

0 comments on commit d1c88c2

Please sign in to comment.