Skip to content
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

fix(connections): add FK to end users #2883

Merged
merged 6 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -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`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we not do that in one single query:

ALTER TABLE "_nango_connections" 
  ADD COLUMN "end_user_id" int4,
  ADD FOREIGN KEY ("end_user_id") REFERENCES "end_users" ("id") ON DELETE SET NULL;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure I could, not sure what would be the benefit, it's 2 different queries


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"`);
};
1 change: 1 addition & 0 deletions packages/server/lib/controllers/oauth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/shared/lib/models/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface OAuthSession {
callbackUrl: string;
authMode: AuthModeType;
id: string;
connectSessionId: number | null;
connectionConfig: Record<string, string>;
environmentId: number;
webSocketClientId: string | undefined;
Expand Down
1 change: 1 addition & 0 deletions packages/shared/lib/models/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type ConnectionConfig = Record<string, any>;
export interface BaseConnection extends TimestampsAndDeleted {
id?: number;
config_id?: number;
end_user_id?: number;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined on purpose until I fix the implementation

provider_config_key: string; // TO deprecate
connection_id: string;
connection_config: ConnectionConfig;
Expand Down
1 change: 1 addition & 0 deletions packages/types/lib/connection/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type ConnectionConfig = Record<string, any>;
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;
Expand Down
Loading