Keep the same site resource id

This commit is contained in:
Owen
2025-12-17 17:36:22 -05:00
committed by Owen Schwartz
parent bb43e0c325
commit c2e06725a8
2 changed files with 15 additions and 20 deletions

View File

@@ -114,16 +114,6 @@ export async function applyBlueprint({
result.oldSiteResource.siteId !=
result.newSiteResource.siteId
) {
// the site resource has moved sites
// insert it first so we get a new siteResourceId just in case
const [insertedSiteResource] = await trx
.insert(siteResources)
.values({
...result.oldSiteResource,
siteResourceId: undefined // to generate a new one
})
.returning();
// query existing associations
const existingRoleIds = await trx
.select()
@@ -168,6 +158,13 @@ export async function applyBlueprint({
trx
);
const [insertedSiteResource] = await trx
.insert(siteResources)
.values({
...result.oldSiteResource,
})
.returning();
// wait some time to allow for messages to be handled
await new Promise((resolve) => setTimeout(resolve, 750));

View File

@@ -245,16 +245,6 @@ export async function updateSiteResource(
await db.transaction(async (trx) => {
// if the site is changed we need to delete and recreate the resource to avoid complications with the rebuild function otherwise we can just update in place
if (siteChanged) {
// create the new site resource from the removed one with the new siteId and updated fields
// insert it first so we get a new siteResourceId just in case
const [insertedSiteResource] = await trx
.insert(siteResources)
.values({
...existingSiteResource,
siteResourceId: undefined // to generate a new one
})
.returning();
// delete the existing site resource
await trx
.delete(siteResources)
@@ -267,6 +257,14 @@ export async function updateSiteResource(
trx
);
// create the new site resource from the removed one - the ID should stay the same
const [insertedSiteResource] = await trx
.insert(siteResources)
.values({
...existingSiteResource,
})
.returning();
// wait some time to allow for messages to be handled
await new Promise((resolve) => setTimeout(resolve, 750));