-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(Notifications): Refactor notification settings to be per team
Previously although meant to be per team, the settings were still tied to a specific auth object. This meant that 1 team could have different conflicting settings.
- Loading branch information
1 parent
e8c4e70
commit 6c7e914
Showing
10 changed files
with
231 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...ver/postgres/migrations/2025-02-18T17:28:11.536Z_notificationSettingsPerTeamAndChannel.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import {sql, type Kysely} from 'kysely' | ||
|
||
export async function up(db: Kysely<any>): Promise<void> { | ||
// Schema changes significantly, easier to create a new table | ||
await db.schema | ||
.createTable('TeamNotificationSettings') | ||
.addColumn('id', 'serial', (col) => col.primaryKey()) | ||
.addColumn('providerId', 'integer', (col) => | ||
col.references('IntegrationProvider.id').onDelete('cascade').notNull() | ||
) | ||
.addColumn('teamId', 'varchar(100)', (col) => | ||
col.references('Team.id').onDelete('cascade').notNull() | ||
) | ||
.addColumn('channelId', 'varchar(255)') | ||
.addColumn('events', sql`"SlackNotificationEventEnum"[]`, (col) => | ||
col.defaultTo(sql`enum_range(NULL::"SlackNotificationEventEnum")`).notNull() | ||
) | ||
.addUniqueConstraint( | ||
'TeamNotificationSettings_providerId_teamId_channelId_key', | ||
['providerId', 'teamId', 'channelId'], | ||
(uc) => uc.nullsNotDistinct() | ||
) | ||
.execute() | ||
|
||
await db | ||
.insertInto('TeamNotificationSettings') | ||
.columns(['providerId', 'teamId', 'events']) | ||
.expression((eb) => | ||
eb | ||
.selectFrom('NotificationSettings') | ||
.innerJoin('TeamMemberIntegrationAuth as auth', 'authId', 'auth.id') | ||
.select(['providerId', 'auth.teamId', sql`array_agg(event)`]) | ||
// There was a bug which might have added settings for other providers like gcal | ||
.where((eb) => eb.or([eb('service', '=', 'mattermost'), eb('service', '=', 'msTeams')])) | ||
.groupBy(['providerId', 'auth.teamId']) | ||
) | ||
.execute() | ||
|
||
/* dropping the old table will be done in a later change | ||
await db.schema | ||
.dropTable('NotificationSettings') | ||
.execute() | ||
*/ | ||
} | ||
|
||
export async function down(db: Kysely<any>): Promise<void> { | ||
/* | ||
await db.schema | ||
.createTable('NotificationSettings') | ||
.addColumn('id', 'serial', (col) => col.primaryKey()) | ||
.addColumn('authId', 'integer', (col) => | ||
col.references('TeamMemberIntegrationAuth.id').onDelete('cascade').notNull() | ||
) | ||
.addColumn('event', sql`"SlackNotificationEventEnum"`, (col) => col.notNull()) | ||
.addUniqueConstraint('NotificationSettings_authId_event_key', ['authId', 'event']) | ||
.execute() | ||
await db.schema | ||
.createIndex('NotificationSettings_authId_idx') | ||
.on('NotificationSettings') | ||
.column('authId') | ||
.execute() | ||
await db | ||
.insertInto('NotificationSettings') | ||
.columns(['authId', 'event']) | ||
.expression((eb) => | ||
eb | ||
.selectFrom('TeamMemberIntegrationAuth as auth') | ||
.innerJoin('TeamNotificationSettings as settings', (join) => join | ||
.onRef('auth.teamId', '=', 'settings.teamId') | ||
.onRef('auth.providerId', '=', 'settings.providerId') | ||
) | ||
.select(['auth.id', sql`unnest(events)`]) | ||
) | ||
.execute() | ||
*/ | ||
|
||
await db.schema.dropTable('TeamNotificationSettings').execute() | ||
} |
Oops, something went wrong.