Skip to content

feat: base code for providerChains and chainMembers #449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
be51d65
chore: migration for fallback provider feature (#437)
kshitij-k-osmosys Jun 30, 2025
892bdf8
feat: configure entities for fallback provider chains (#438)
kshitij-k-osmosys Jun 30, 2025
db7ee35
chore: squash and merge changes from branch main
kshitij-k-osmosys Jul 16, 2025
c891878
chore: squash and merge branch main
kshitij-k-osmosys Jul 20, 2025
33cebc9
fix: remove unnecessary foreign key for channelType in provider_chains
kshitij-k-osmosys Jul 14, 2025
f2c031d
fix: use providerType enums
kshitij-k-osmosys Jul 14, 2025
0c88046
feat: rename column channel_type to provider_type
kshitij-k-osmosys Jul 20, 2025
5be123c
chore: update migration timestamp
kshitij-k-osmosys Jul 20, 2025
790238d
feat: add foreign key FK_PROVIDER_CHAINS_PROVIDER_TYPE
kshitij-k-osmosys Jul 20, 2025
3024888
feat: create provider-chains module and service
kshitij-k-osmosys Jul 13, 2025
2c1dfed
feat: create provider-chain-members module and service
kshitij-k-osmosys Jul 13, 2025
1d47152
chore: export services to enable dependency injection
kshitij-k-osmosys Jul 20, 2025
7d6db08
Merge branch 'main' into feat/fallback-provider-migration-and-base-code
kshitij-k-osmosys Jul 20, 2025
ee9b9cc
fix: make description nullable
kshitij-k-osmosys Jul 20, 2025
5652802
style: use camelCase
kshitij-k-osmosys Jul 20, 2025
42f3b7e
refactor: keep provider modules together
kshitij-k-osmosys Jul 20, 2025
25373e9
feat: get first chain member service fn
kshitij-k-osmosys Jul 20, 2025
1a9395b
fix: on delete behavior for FK_PROVIDER_CHAINS_PROVIDER_TYPE
kshitij-k-osmosys Jul 20, 2025
1ffaef7
refactor: remove redundant constant
kshitij-k-osmosys Jul 20, 2025
51eb34c
style: fix constructor parameter name
kshitij-k-osmosys Jul 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/api/src/common/constants/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ export const IsEnabledStatus = {
FALSE: 0,
TRUE: 1,
};

export const IsDefaultStatus = {
FALSE: 0,
TRUE: 1,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,354 @@
import {
MigrationInterface,
QueryRunner,
Table,
TableColumn,
TableForeignKey,
TableIndex,
TableUnique,
} from 'typeorm';

export class FallbackProviderChanges1752904253632 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
// 1. Create notify_provider_chains table
await queryRunner.createTable(
new Table({
name: 'notify_provider_chains',
columns: [
{
name: 'chain_id',
type: 'int',
isPrimary: true,
isGenerated: true,
generationStrategy: 'increment',
},
{
name: 'chain_name',
type: 'varchar',
length: '255',
isNullable: false,
},
{
name: 'application_id',
type: 'int',
isNullable: false,
},
{
name: 'provider_type',
type: 'smallint',
isNullable: false,
},
{
name: 'description',
type: 'text',
isNullable: true,
},
{
name: 'is_default',
type: 'smallint',
default: '0',
isNullable: false,
},
{
name: 'created_on',
type: 'timestamp',
default: 'CURRENT_TIMESTAMP',
isNullable: false,
},
{
name: 'updated_on',
type: 'timestamp',
default: 'CURRENT_TIMESTAMP',
onUpdate: 'CURRENT_TIMESTAMP',
isNullable: false,
},
{
name: 'status',
type: 'smallint',
default: '1',
isNullable: false,
},
],
}),
true,
);

// 2. Create notify_provider_chain_members table
await queryRunner.createTable(
new Table({
name: 'notify_provider_chain_members',
columns: [
{
name: 'id',
type: 'int',
isPrimary: true,
isGenerated: true,
generationStrategy: 'increment',
},
{
name: 'chain_id',
type: 'int',
isNullable: false,
},
{
name: 'provider_id',
type: 'int',
isNullable: false,
},
{
name: 'priority_order',
type: 'smallint',
isNullable: false,
},
{
name: 'is_active',
type: 'smallint',
default: '1',
isNullable: false,
},
{
name: 'created_on',
type: 'timestamp',
default: 'CURRENT_TIMESTAMP',
isNullable: false,
},
{
name: 'updated_on',
type: 'timestamp',
default: 'CURRENT_TIMESTAMP',
onUpdate: 'CURRENT_TIMESTAMP',
isNullable: false,
},
{
name: 'status',
type: 'smallint',
default: '1',
isNullable: false,
},
],
}),
true,
);

// 3. Add Foreign Key Constraints for notify_provider_chains
await queryRunner.createForeignKey(
'notify_provider_chains',
new TableForeignKey({
columnNames: ['application_id'],
referencedColumnNames: ['application_id'],
referencedTableName: 'notify_applications',
onDelete: 'CASCADE',
name: 'FK_PROVIDER_CHAINS_APPLICATION',
}),
);

await queryRunner.createForeignKey(
'notify_provider_chains',
new TableForeignKey({
columnNames: ['provider_type'],
referencedColumnNames: ['provider_type_id'],
referencedTableName: 'notify_provider_types',
onDelete: 'SET NULL',
name: 'FK_PROVIDER_CHAINS_PROVIDER_TYPE',
}),
);

// 4. Add Foreign Key Constraints for notify_provider_chain_members
await queryRunner.createForeignKey(
'notify_provider_chain_members',
new TableForeignKey({
columnNames: ['chain_id'],
referencedColumnNames: ['chain_id'],
referencedTableName: 'notify_provider_chains',
onDelete: 'CASCADE',
name: 'FK_CHAIN_MEMBERS_CHAIN',
}),
);

await queryRunner.createForeignKey(
'notify_provider_chain_members',
new TableForeignKey({
columnNames: ['provider_id'],
referencedColumnNames: ['provider_id'],
referencedTableName: 'notify_providers',
onDelete: 'CASCADE',
name: 'FK_CHAIN_MEMBERS_PROVIDER',
}),
);

// 5. Create Indexes for notify_provider_chains
await queryRunner.createIndex(
'notify_provider_chains',
new TableIndex({
columnNames: ['application_id', 'provider_type'],
name: 'IDX_CHAINS_APPLICATION_CHANNEL',
}),
);

await queryRunner.createIndex(
'notify_provider_chains',
new TableIndex({
columnNames: ['status'],
name: 'IDX_CHAINS_STATUS',
}),
);

await queryRunner.createIndex(
'notify_provider_chains',
new TableIndex({
columnNames: ['application_id', 'provider_type', 'is_default'],
name: 'IDX_CHAINS_DEFAULT',
}),
);

// 6. Create Indexes for notify_provider_chain_members
await queryRunner.createIndex(
'notify_provider_chain_members',
new TableIndex({
columnNames: ['chain_id', 'priority_order'],
name: 'IDX_CHAIN_MEMBERS_CHAIN_ORDER',
}),
);

await queryRunner.createIndex(
'notify_provider_chain_members',
new TableIndex({
columnNames: ['provider_id'],
name: 'IDX_CHAIN_MEMBERS_PROVIDER',
}),
);

await queryRunner.createIndex(
'notify_provider_chain_members',
new TableIndex({
columnNames: ['status'],
name: 'IDX_CHAIN_MEMBERS_STATUS',
}),
);

// 7. Add Unique Constraints for both tables
await queryRunner.createUniqueConstraint(
'notify_provider_chains',
new TableUnique({
columnNames: ['application_id', 'chain_name'],
name: 'UQ_APP_CHAIN_NAME',
}),
);

await queryRunner.createUniqueConstraint(
'notify_provider_chain_members',
new TableUnique({
columnNames: ['chain_id', 'priority_order'],
name: 'UQ_CHAIN_PRIORITY',
}),
);

await queryRunner.createUniqueConstraint(
'notify_provider_chain_members',
new TableUnique({
columnNames: ['chain_id', 'provider_id'],
name: 'UQ_CHAIN_PROVIDER',
}),
);

// 8. Table modifications for notify_notifications
await queryRunner.addColumn(
'notify_notifications',
new TableColumn({
name: 'provider_chain_id',
type: 'int',
isNullable: true,
}),
);

await queryRunner.createForeignKey(
'notify_notifications',
new TableForeignKey({
columnNames: ['provider_chain_id'],
referencedColumnNames: ['chain_id'],
referencedTableName: 'notify_provider_chains',
onDelete: 'SET NULL',
name: 'FK_NOTIFICATIONS_PROVIDER_CHAIN',
}),
);

await queryRunner.createIndex(
'notify_notifications',
new TableIndex({
columnNames: ['provider_chain_id'],
name: 'IDX_NOTIFICATIONS_PROVIDER_CHAIN',
}),
);

// 9. Table modifications for notify_archived_notifications
await queryRunner.addColumn(
'notify_archived_notifications',
new TableColumn({
name: 'provider_chain_id',
type: 'int',
isNullable: true,
}),
);

await queryRunner.createForeignKey(
'notify_archived_notifications',
new TableForeignKey({
columnNames: ['provider_chain_id'],
referencedColumnNames: ['chain_id'],
referencedTableName: 'notify_provider_chains',
onDelete: 'SET NULL',
name: 'FK_ARCHIVED_NOTIFICATIONS_PROVIDER_CHAIN',
}),
);

await queryRunner.createIndex(
'notify_archived_notifications',
new TableIndex({
columnNames: ['provider_chain_id'],
name: 'IDX_ARCHIVED_NOTIFICATIONS_PROVIDER_CHAIN',
}),
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
// 1. Revert changes from table notify_archived_notifications
await queryRunner.dropIndex(
'notify_archived_notifications',
'IDX_ARCHIVED_NOTIFICATIONS_PROVIDER_CHAIN',
);
await queryRunner.dropForeignKey(
'notify_archived_notifications',
'FK_ARCHIVED_NOTIFICATIONS_PROVIDER_CHAIN',
);
await queryRunner.dropColumn('notify_archived_notifications', 'provider_chain_id');

// 2. Revert changes from table notify_notifications
await queryRunner.dropIndex('notify_notifications', 'IDX_NOTIFICATIONS_PROVIDER_CHAIN');
await queryRunner.dropForeignKey('notify_notifications', 'FK_NOTIFICATIONS_PROVIDER_CHAIN');
await queryRunner.dropColumn('notify_notifications', 'provider_chain_id');

// 3. Drop Unique Constraints
await queryRunner.dropUniqueConstraint('notify_provider_chain_members', 'UQ_CHAIN_PROVIDER');
await queryRunner.dropUniqueConstraint('notify_provider_chain_members', 'UQ_CHAIN_PRIORITY');
await queryRunner.dropUniqueConstraint('notify_provider_chains', 'UQ_APP_CHAIN_NAME');

// 4. Drop Indexes
await queryRunner.dropIndex('notify_provider_chain_members', 'IDX_CHAIN_MEMBERS_STATUS');
await queryRunner.dropIndex('notify_provider_chain_members', 'IDX_CHAIN_MEMBERS_PROVIDER');
await queryRunner.dropIndex('notify_provider_chain_members', 'IDX_CHAIN_MEMBERS_CHAIN_ORDER');

await queryRunner.dropIndex('notify_provider_chains', 'IDX_CHAINS_DEFAULT');
await queryRunner.dropIndex('notify_provider_chains', 'IDX_CHAINS_STATUS');
await queryRunner.dropIndex('notify_provider_chains', 'IDX_CHAINS_APPLICATION_CHANNEL');

// 5. Drop Foreign Key Constraints
await queryRunner.dropForeignKey('notify_provider_chain_members', 'FK_CHAIN_MEMBERS_PROVIDER');
await queryRunner.dropForeignKey('notify_provider_chain_members', 'FK_CHAIN_MEMBERS_CHAIN');
await queryRunner.dropForeignKey('notify_provider_chains', 'FK_PROVIDER_CHAINS_PROVIDER_TYPE');
await queryRunner.dropForeignKey('notify_provider_chains', 'FK_PROVIDER_CHAINS_APPLICATION');

// 6. Drop tables in reverse order of creation to respect dependencies
await queryRunner.dropTable('notify_provider_chain_members');
await queryRunner.dropTable('notify_provider_chains');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Notification } from 'src/modules/notifications/entities/notification.en
import { ServerApiKey } from 'src/modules/server-api-keys/entities/server-api-key.entity';
import { ArchivedNotification } from 'src/modules/archived-notifications/entities/archived-notification.entity';
import { GraphQLJSONObject } from 'graphql-type-json';
import { ProviderChain } from 'src/modules/provider-chains/entities/provider-chain.entity';

@Entity({ name: 'notify_applications' })
@ObjectType()
Expand Down Expand Up @@ -76,6 +77,10 @@ export class Application {
)
archivedNotifications: ArchivedNotification[];

@OneToMany(() => ProviderChain, (providerChain) => providerChain.applicationDetails)
@Field(() => [ProviderChain], { nullable: true })
providerChains: ProviderChain[];

constructor(application: Partial<Application>) {
Object.assign(this, application);
}
Expand Down
Loading
Loading