mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-31 18:59:19 +00:00
Add userInviteRoles migration
This commit is contained in:
@@ -20,6 +20,19 @@ export default async function migration() {
|
||||
`Found ${existingUserOrgRoles.length} existing userOrgs role assignment(s) to migrate`
|
||||
);
|
||||
|
||||
// Query existing roleId data from userInvites before the transaction destroys it
|
||||
const existingInviteRolesQuery = await db.execute(
|
||||
sql`SELECT "inviteId", "roleId" FROM "userInvites" WHERE "roleId" IS NOT NULL`
|
||||
);
|
||||
const existingUserInviteRoles = existingInviteRolesQuery.rows as {
|
||||
inviteId: string;
|
||||
roleId: number;
|
||||
}[];
|
||||
|
||||
console.log(
|
||||
`Found ${existingUserInviteRoles.length} existing userInvites role assignment(s) to migrate`
|
||||
);
|
||||
|
||||
try {
|
||||
await db.execute(sql`BEGIN`);
|
||||
|
||||
@@ -174,6 +187,29 @@ export default async function migration() {
|
||||
throw e;
|
||||
}
|
||||
|
||||
// Re-insert the preserved invite role assignments into the new userInviteRoles table
|
||||
if (existingUserInviteRoles.length > 0) {
|
||||
try {
|
||||
for (const row of existingUserInviteRoles) {
|
||||
await db.execute(sql`
|
||||
INSERT INTO "userInviteRoles" ("inviteId", "roleId")
|
||||
VALUES (${row.inviteId}, ${row.roleId})
|
||||
ON CONFLICT DO NOTHING
|
||||
`);
|
||||
}
|
||||
|
||||
console.log(
|
||||
`Migrated ${existingUserInviteRoles.length} role assignment(s) into userInviteRoles`
|
||||
);
|
||||
} catch (e) {
|
||||
console.error(
|
||||
"Error while migrating role assignments into userInviteRoles:",
|
||||
e
|
||||
);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// Re-insert the preserved role assignments into the new userOrgRoles table
|
||||
if (existingUserOrgRoles.length > 0) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user