mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-06 10:46:38 +00:00
Update sqlite migration to update caches
This commit is contained in:
@@ -271,6 +271,12 @@ export default async function migration() {
|
|||||||
const insertClientSiteResource = db.prepare(
|
const insertClientSiteResource = db.prepare(
|
||||||
`INSERT INTO 'clientSiteResources' ('clientId', 'siteResourceId') VALUES (?, ?)`
|
`INSERT INTO 'clientSiteResources' ('clientId', 'siteResourceId') VALUES (?, ?)`
|
||||||
);
|
);
|
||||||
|
const insertClientSiteResourceAssocCache = db.prepare(
|
||||||
|
`INSERT INTO 'clientSiteResourcesAssociationsCache' ('clientId', 'siteResourceId') VALUES (?, ?)`
|
||||||
|
);
|
||||||
|
const insertClientSiteAssocCache = db.prepare(
|
||||||
|
`INSERT INTO 'clientSitesAssociationsCache' ('clientId', 'siteId', 'isRelayed', 'endpoint', 'publicKey') VALUES (?, ?, false, NULL, NULL)`
|
||||||
|
);
|
||||||
|
|
||||||
for (const client of clients) {
|
for (const client of clients) {
|
||||||
for (const siteResource of siteResources) {
|
for (const siteResource of siteResources) {
|
||||||
@@ -278,14 +284,33 @@ export default async function migration() {
|
|||||||
client.clientId,
|
client.clientId,
|
||||||
siteResource.siteResourceId
|
siteResource.siteResourceId
|
||||||
);
|
);
|
||||||
|
insertClientSiteResourceAssocCache.run(
|
||||||
|
client.clientId,
|
||||||
|
siteResource.siteResourceId
|
||||||
|
);
|
||||||
|
// check if clientSitesAssociationsCache already has an entry for this clientId and siteId
|
||||||
|
const siteIdRow = db
|
||||||
|
.prepare(
|
||||||
|
`SELECT siteId FROM 'siteResources' WHERE siteResourceId = ? LIMIT 1`
|
||||||
|
)
|
||||||
|
.get(siteResource.siteResourceId) as { siteId: number };
|
||||||
|
const existing = db
|
||||||
|
.prepare(
|
||||||
|
`SELECT 1 FROM 'clientSitesAssociationsCache' WHERE clientId = ? AND siteId = ? LIMIT 1`
|
||||||
|
)
|
||||||
|
.get(client.clientId, siteIdRow.siteId);
|
||||||
|
if (!existing) {
|
||||||
|
insertClientSiteAssocCache.run(
|
||||||
|
client.clientId,
|
||||||
|
siteIdRow.siteId
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Associate existing site resources with their org's admin role
|
// Associate existing site resources with their org's admin role
|
||||||
const siteResourcesWithOrg = db
|
const siteResourcesWithOrg = db
|
||||||
.prepare(
|
.prepare(`SELECT siteResourceId, orgId FROM 'siteResources'`)
|
||||||
`SELECT siteResourceId, orgId FROM 'siteResources'`
|
|
||||||
)
|
|
||||||
.all() as {
|
.all() as {
|
||||||
siteResourceId: number;
|
siteResourceId: number;
|
||||||
orgId: string;
|
orgId: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user