mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-03 09:16:40 +00:00
Keep the same site resource id
This commit is contained in:
@@ -114,16 +114,6 @@ export async function applyBlueprint({
|
|||||||
result.oldSiteResource.siteId !=
|
result.oldSiteResource.siteId !=
|
||||||
result.newSiteResource.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
|
// query existing associations
|
||||||
const existingRoleIds = await trx
|
const existingRoleIds = await trx
|
||||||
.select()
|
.select()
|
||||||
@@ -168,6 +158,13 @@ export async function applyBlueprint({
|
|||||||
trx
|
trx
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const [insertedSiteResource] = await trx
|
||||||
|
.insert(siteResources)
|
||||||
|
.values({
|
||||||
|
...result.oldSiteResource,
|
||||||
|
})
|
||||||
|
.returning();
|
||||||
|
|
||||||
// wait some time to allow for messages to be handled
|
// wait some time to allow for messages to be handled
|
||||||
await new Promise((resolve) => setTimeout(resolve, 750));
|
await new Promise((resolve) => setTimeout(resolve, 750));
|
||||||
|
|
||||||
|
|||||||
@@ -245,16 +245,6 @@ export async function updateSiteResource(
|
|||||||
await db.transaction(async (trx) => {
|
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 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) {
|
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
|
// delete the existing site resource
|
||||||
await trx
|
await trx
|
||||||
.delete(siteResources)
|
.delete(siteResources)
|
||||||
@@ -267,6 +257,14 @@ export async function updateSiteResource(
|
|||||||
trx
|
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
|
// wait some time to allow for messages to be handled
|
||||||
await new Promise((resolve) => setTimeout(resolve, 750));
|
await new Promise((resolve) => setTimeout(resolve, 750));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user