diff --git a/packages/database/lib/migrations/20241024094439_connections_end_user.cjs b/packages/database/lib/migrations/20241024094439_connections_end_user.cjs new file mode 100644 index 0000000000..88fa40a13f --- /dev/null +++ b/packages/database/lib/migrations/20241024094439_connections_end_user.cjs @@ -0,0 +1,18 @@ +/** + * @param {import('knex').Knex} knex + */ +exports.up = async function (knex) { + await knex.raw(`ALTER TABLE "_nango_connections" ADD COLUMN "end_user_id" int4`); + await knex.raw(`ALTER TABLE "_nango_connections" ADD FOREIGN KEY ("end_user_id") REFERENCES "end_users" ("id") ON DELETE SET NULL`); + + await knex.raw(`ALTER TABLE "_nango_oauth_sessions" ADD COLUMN "connect_session_id" int4`); + await knex.raw(`ALTER TABLE "_nango_oauth_sessions" ADD FOREIGN KEY ("connect_session_id") REFERENCES "connect_sessions" ("id") ON DELETE SET NULL`); +}; + +/** + * @param {import('knex').Knex} knex + */ +exports.down = async function (knex) { + await knex.raw(`ALTER TABLE "_nango_connections" DROP COLUMN "end_user_id"`); + await knex.raw(`ALTER TABLE "_nango_oauth_sessions" DROP COLUMN "connect_session_id"`); +}; diff --git a/packages/server/lib/controllers/oauth.controller.ts b/packages/server/lib/controllers/oauth.controller.ts index 9a77603da8..0b3032025c 100644 --- a/packages/server/lib/controllers/oauth.controller.ts +++ b/packages/server/lib/controllers/oauth.controller.ts @@ -146,6 +146,7 @@ class OAuthController { authMode: provider.auth_mode, codeVerifier: crypto.randomBytes(24).toString('hex'), id: uuid.v1(), + connectSessionId: null, connectionConfig, environmentId, webSocketClientId: wsClientId, diff --git a/packages/shared/lib/models/Auth.ts b/packages/shared/lib/models/Auth.ts index 19ef5a5c1d..1663565c41 100644 --- a/packages/shared/lib/models/Auth.ts +++ b/packages/shared/lib/models/Auth.ts @@ -24,6 +24,7 @@ export interface OAuthSession { callbackUrl: string; authMode: AuthModeType; id: string; + connectSessionId: number | null; connectionConfig: Record; environmentId: number; webSocketClientId: string | undefined; diff --git a/packages/shared/lib/models/Connection.ts b/packages/shared/lib/models/Connection.ts index 6888621d39..3f3dc5101b 100644 --- a/packages/shared/lib/models/Connection.ts +++ b/packages/shared/lib/models/Connection.ts @@ -7,6 +7,7 @@ export type ConnectionConfig = Record; export interface BaseConnection extends TimestampsAndDeleted { id?: number; config_id?: number; + end_user_id?: number; provider_config_key: string; // TO deprecate connection_id: string; connection_config: ConnectionConfig; diff --git a/packages/types/lib/connection/db.ts b/packages/types/lib/connection/db.ts index 66ec6e5866..62150f562d 100644 --- a/packages/types/lib/connection/db.ts +++ b/packages/types/lib/connection/db.ts @@ -10,6 +10,7 @@ export type ConnectionConfig = Record; export interface BaseConnection extends TimestampsAndDeleted { id?: number; config_id?: number; + end_user_id?: number; provider_config_key: string; // TO deprecate connection_id: string; connection_config: ConnectionConfig;