Skip to content

Commit

Permalink
migrate auth.user.teamId to orgId (#312)
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Sutula <[email protected]>
Co-authored-by: Aaron Sutula <[email protected]>
  • Loading branch information
asutula and asutula authored Aug 13, 2024
1 parent cc22f0c commit b7788fa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 10 additions & 1 deletion packages/api/src/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,20 @@ export interface GetSessionArgs {
export const createTRPCContext = async (args: GetSessionArgs) => {
const session = await getSession(args);

// Migrate personalTeam to personalOrg.
// Migrate personalTeam to personalOrg and teamId to orgId.
// TODO: Remove this after it runs for a while.
let dirty = false;
if (session.auth?.personalTeam) {
session.auth.personalOrg = session.auth.personalTeam;
session.auth.personalTeam = undefined;
dirty = true;
}
if (session.auth?.user.teamId) {
session.auth.user.orgId = session.auth.user.teamId;
session.auth.user.teamId = undefined;
dirty = true;
}
if (dirty) {
await session.save();
}

Expand Down
5 changes: 4 additions & 1 deletion packages/store/src/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ export type NewDef = InferInsertModel<typeof defs>;
export type UserSealed = InferSelectModel<typeof users>;
export type NewUserSealed = InferInsertModel<typeof users>;

export type User = Omit<UserSealed, "sealed"> & { email?: string };
export type User = Omit<UserSealed, "sealed"> & {
email?: string;
teamId?: string; // TODO: remove this after running the migration for a while.
};
export type NewUser = Omit<NewUserSealed, "sealed"> & {
email?: string;
};
Expand Down

1 comment on commit b7788fa

@vercel
Copy link

@vercel vercel bot commented on b7788fa Aug 13, 2024

Choose a reason for hiding this comment

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

Please sign in to comment.