mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-10 12:46:37 +00:00
migrate autoProvisioned on user based on idp autoProvision
This commit is contained in:
@@ -94,6 +94,25 @@ export default async function migration() {
|
|||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle auto-provisioned users for identity providers
|
||||||
|
const autoProvisionIdps = await db.execute(sql`
|
||||||
|
SELECT "idpId" FROM "idp" WHERE "autoProvision" = true
|
||||||
|
`);
|
||||||
|
|
||||||
|
for (const idp of autoProvisionIdps.rows) {
|
||||||
|
// Get all users with this identity provider
|
||||||
|
const usersWithIdp = await db.execute(sql`
|
||||||
|
SELECT "id" FROM "user" WHERE "idpId" = ${idp.idpId}
|
||||||
|
`);
|
||||||
|
|
||||||
|
// Update userOrgs to set autoProvisioned to true for these users
|
||||||
|
for (const user of usersWithIdp.rows) {
|
||||||
|
await db.execute(sql`
|
||||||
|
UPDATE "userOrgs" SET "autoProvisioned" = true WHERE "userId" = ${user.id}
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await db.execute(sql`COMMIT`);
|
await db.execute(sql`COMMIT`);
|
||||||
console.log(`Migrated database`);
|
console.log(`Migrated database`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -11,9 +11,6 @@ export default async function migration() {
|
|||||||
const location = path.join(APP_PATH, "db", "db.sqlite");
|
const location = path.join(APP_PATH, "db", "db.sqlite");
|
||||||
const db = new Database(location);
|
const db = new Database(location);
|
||||||
|
|
||||||
const resourceSiteMap = new Map<number, number>();
|
|
||||||
const firstSiteId: number = 1;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const resources = db
|
const resources = db
|
||||||
.prepare(
|
.prepare(
|
||||||
@@ -82,6 +79,29 @@ export default async function migration() {
|
|||||||
`UPDATE siteResources SET niceId = ? WHERE siteResourceId = ?`
|
`UPDATE siteResources SET niceId = ? WHERE siteResourceId = ?`
|
||||||
).run(niceId, resourceId.siteResourceId);
|
).run(niceId, resourceId.siteResourceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle auto-provisioned users for identity providers
|
||||||
|
const autoProvisionIdps = db
|
||||||
|
.prepare(
|
||||||
|
"SELECT idpId FROM idp WHERE autoProvision = 1"
|
||||||
|
)
|
||||||
|
.all() as Array<{ idpId: number }>;
|
||||||
|
|
||||||
|
for (const idp of autoProvisionIdps) {
|
||||||
|
// Get all users with this identity provider
|
||||||
|
const usersWithIdp = db
|
||||||
|
.prepare(
|
||||||
|
"SELECT id FROM user WHERE idpId = ?"
|
||||||
|
)
|
||||||
|
.all(idp.idpId) as Array<{ id: string }>;
|
||||||
|
|
||||||
|
// Update userOrgs to set autoProvisioned to true for these users
|
||||||
|
for (const user of usersWithIdp) {
|
||||||
|
db.prepare(
|
||||||
|
"UPDATE userOrgs SET autoProvisioned = 1 WHERE userId = ?"
|
||||||
|
).run(user.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
console.log(`Migrated database`);
|
console.log(`Migrated database`);
|
||||||
|
|||||||
Reference in New Issue
Block a user