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

feat: remove legacy auth0 user accounts #6066

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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,31 @@
import { type MigrationExecutor } from '../pg-migrator';

export default {
name: '2024.12.02T00-00-00.legacy-user-org-cleanup.ts',
async run({ sql, connection }) {
// Delete all the organizations owned by a legacy user
await connection.query(sql`
DELETE
FROM
"organizations"
WHERE
"user_id" = ANY(
SELECT
"id"
FROM
"users"
WHERE
"supertoken_user_id" IS NULL
)
Comment on lines +7 to +19
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no cascade trigger for the "organizations"."user_id" foreign key constraint, so we first delete the organizations.

`);

// Delete all the legacy users
await connection.query(sql`
DELETE
FROM
"users"
WHERE
"supertoken_user_id" IS NULL
`);
},
} satisfies MigrationExecutor;
1 change: 1 addition & 0 deletions packages/migrations/src/run-pg-migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,6 @@ export const runPGMigrations = async (args: { slonik: DatabasePool; runTo?: stri
await import('./actions/2024.11.12T00-00-00.supertokens-9.1'),
await import('./actions/2024.11.12T00-00-00.supertokens-9.2'),
await import('./actions/2024.11.12T00-00-00.supertokens-9.3'),
await import('./actions/2024.12.02T00-00-00.legacy-user-org-cleanup'),
],
});
Original file line number Diff line number Diff line change
Expand Up @@ -969,9 +969,8 @@ export class SchemaManager {
return null;
}

return this.storage.getOrganizationUser({
organizationId: args.organizationId,
userId: args.userId,
return this.storage.getUserById({
id: args.userId,
});
}

Expand Down
6 changes: 0 additions & 6 deletions packages/services/api/src/modules/shared/providers/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export interface Storage {
isReady(): Promise<boolean>;
ensureUserExists(_: {
superTokensUserId: string;
externalAuthUserId?: string | null;
email: string;
oidcIntegration: null | {
id: string;
Expand Down Expand Up @@ -848,11 +847,6 @@ export interface Storage {

getTargetBreadcrumbForTargetId(_: { targetId: string }): Promise<TargetBreadcrumb | null>;

/**
* Get an user that belongs to a specific organization by id.
*/
getOrganizationUser(_: { organizationId: string; userId: string }): Promise<User | null>;

// Zendesk
setZendeskUserId(_: { userId: string; zendeskId: string }): Promise<void>;
setZendeskOrganizationId(_: { organizationId: string; zendeskId: string }): Promise<void>;
Expand Down
2 changes: 1 addition & 1 deletion packages/services/api/src/shared/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export interface Organization {
appDeployments: boolean;
};
zendeskId: string | null;
ownerId: string;
}

export interface OrganizationInvitation {
Expand Down Expand Up @@ -330,7 +331,6 @@ export interface User {
provider: AuthProvider;
superTokensUserId: string | null;
isAdmin: boolean;
externalAuthUserId: string | null;
oidcIntegrationId: string | null;
zendeskId: string | null;
}
Expand Down
Loading
Loading