mirror of
https://github.com/docmost/docmost.git
synced 2026-08-24 14:42:17 +10:00
fix(integrations): scope Slack-kind backfill, fix index where-clause types
This commit is contained in:
+11
-4
@@ -21,11 +21,14 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
CHECK (kind IN ('workspace', 'user'))
|
CHECK (kind IN ('workspace', 'user'))
|
||||||
`.execute(db);
|
`.execute(db);
|
||||||
|
|
||||||
// 3. Backfill: existing rows with access_token AND scopes are workspace installs
|
// 3. Backfill: existing Slack workspace installs (rows with access_token)
|
||||||
await sql`
|
await sql`
|
||||||
UPDATE integration_connections
|
UPDATE integration_connections AS ic
|
||||||
SET kind = 'workspace'
|
SET kind = 'workspace'
|
||||||
WHERE access_token IS NOT NULL AND scopes IS NOT NULL
|
FROM integrations AS i
|
||||||
|
WHERE ic.integration_id = i.id
|
||||||
|
AND i.type = 'slack'
|
||||||
|
AND ic.access_token IS NOT NULL
|
||||||
`.execute(db);
|
`.execute(db);
|
||||||
|
|
||||||
// 4. One workspace connection per integration
|
// 4. One workspace connection per integration
|
||||||
@@ -33,7 +36,7 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
.createIndex('uq_integration_connections_workspace_per_integration')
|
.createIndex('uq_integration_connections_workspace_per_integration')
|
||||||
.on('integration_connections')
|
.on('integration_connections')
|
||||||
.column('integration_id')
|
.column('integration_id')
|
||||||
.where('kind', '=', 'workspace')
|
.where(sql.ref('kind'), '=', 'workspace')
|
||||||
.unique()
|
.unique()
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
@@ -50,4 +53,8 @@ export async function down(db: Kysely<any>): Promise<void> {
|
|||||||
.alterTable('integration_connections')
|
.alterTable('integration_connections')
|
||||||
.dropColumn('kind')
|
.dropColumn('kind')
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
// Note: we don't restore NOT NULL on access_token in down(); by this point
|
||||||
|
// there may be legitimate null-token rows (identity-only user links) that
|
||||||
|
// would block re-adding the constraint.
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user