feat: Auto-fix cost_credits <= 0 to 3 on every furniture import
- Extended fixDatabaseConsistencyAfterImport() to also set cost_credits = 3 where <= 0 - Integrated into both single and batch import routes - API responses now include costCreditsFixed count Ensures 100% of catalog_items have cost_credits > 0 after import - Typecheck, lint, tests all pass - Pushed to GitLab
This commit is contained in:
1 parent
86f3d82c5d
commit
0b0cf4f37f
3 files changed
+30
-14
No files matched your search
@@ -266,8 +266,9 @@ export const POST = withAdmin(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix database consistency (catalog_name + have_offer) after import
|
// Fix database consistency (catalog_name + have_offer + cost_credits) after import
|
||||||
const dbFix = await fixDatabaseConsistencyAfterImport();
|
const { catalogNameFixed, haveOfferFixed, costCreditsFixed } =
|
||||||
|
await fixDatabaseConsistencyAfterImport();
|
||||||
|
|
||||||
send({
|
send({
|
||||||
type: "batch_complete",
|
type: "batch_complete",
|
||||||
@@ -285,8 +286,9 @@ export const POST = withAdmin(
|
|||||||
offerRebuildFixed,
|
offerRebuildFixed,
|
||||||
spriteFixed,
|
spriteFixed,
|
||||||
interactionFixed,
|
interactionFixed,
|
||||||
catalogNameFixed: dbFix.catalogNameFixed,
|
catalogNameFixed,
|
||||||
haveOfferFixed: dbFix.haveOfferFixed,
|
haveOfferFixed,
|
||||||
|
costCreditsFixed,
|
||||||
languages,
|
languages,
|
||||||
duration: Date.now() - startTime,
|
duration: Date.now() - startTime,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -481,8 +481,9 @@ export const POST = withAdmin(
|
|||||||
// Verify + fix interaction_modes_count once for the whole batch
|
// Verify + fix interaction_modes_count once for the whole batch
|
||||||
const verification = await verifyAndFixInteractionModesCount();
|
const verification = await verifyAndFixInteractionModesCount();
|
||||||
|
|
||||||
// Fix database consistency (catalog_name + have_offer) after import
|
// Fix database consistency (catalog_name + have_offer + cost_credits) after import
|
||||||
const dbFix = await fixDatabaseConsistencyAfterImport();
|
const { catalogNameFixed, haveOfferFixed, costCreditsFixed } =
|
||||||
|
await fixDatabaseConsistencyAfterImport();
|
||||||
|
|
||||||
// Rebuild all localized furnidata files (best effort)
|
// Rebuild all localized furnidata files (best effort)
|
||||||
let languages: Awaited<ReturnType<typeof buildLocalizedFurniDataFiles>> =
|
let languages: Awaited<ReturnType<typeof buildLocalizedFurniDataFiles>> =
|
||||||
@@ -517,8 +518,9 @@ export const POST = withAdmin(
|
|||||||
spriteChecked: spriteVerify.checked,
|
spriteChecked: spriteVerify.checked,
|
||||||
spriteFixed: spriteVerify.fixed,
|
spriteFixed: spriteVerify.fixed,
|
||||||
interactionFixed: verification.fixed,
|
interactionFixed: verification.fixed,
|
||||||
catalogNameFixed: dbFix.catalogNameFixed,
|
catalogNameFixed,
|
||||||
haveOfferFixed: dbFix.haveOfferFixed,
|
haveOfferFixed,
|
||||||
|
costCreditsFixed,
|
||||||
languages,
|
languages,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -581,8 +583,9 @@ export const POST = withAdmin(
|
|||||||
// Verify the furnidata matches the DB ids
|
// Verify the furnidata matches the DB ids
|
||||||
const furniReconcile = await reconcileFurniDataWithItemsBase();
|
const furniReconcile = await reconcileFurniDataWithItemsBase();
|
||||||
|
|
||||||
// Fix database consistency (catalog_name + have_offer) after import
|
// Fix database consistency (catalog_name + have_offer + cost_credits) after import
|
||||||
const dbFix = await fixDatabaseConsistencyAfterImport();
|
const { catalogNameFixed, haveOfferFixed, costCreditsFixed } =
|
||||||
|
await fixDatabaseConsistencyAfterImport();
|
||||||
|
|
||||||
// Rebuild every catalog offer_id from the furnidata
|
// Rebuild every catalog offer_id from the furnidata
|
||||||
const offerRebuild = await rebuildCatalogOfferIds();
|
const offerRebuild = await rebuildCatalogOfferIds();
|
||||||
@@ -641,8 +644,9 @@ export const POST = withAdmin(
|
|||||||
spriteChecked: spriteVerify.checked,
|
spriteChecked: spriteVerify.checked,
|
||||||
spriteFixed: spriteVerify.fixed,
|
spriteFixed: spriteVerify.fixed,
|
||||||
interactionFixed: verification.fixed,
|
interactionFixed: verification.fixed,
|
||||||
catalogNameFixed: dbFix.catalogNameFixed,
|
catalogNameFixed,
|
||||||
haveOfferFixed: dbFix.haveOfferFixed,
|
haveOfferFixed,
|
||||||
|
costCreditsFixed,
|
||||||
languages: languagesPatch,
|
languages: languagesPatch,
|
||||||
spriteCount: result.spriteCount,
|
spriteCount: result.spriteCount,
|
||||||
warnings: result.warnings,
|
warnings: result.warnings,
|
||||||
|
|||||||
@@ -1089,10 +1089,12 @@ async function realNitroModes(classname: string): Promise<number | undefined> {
|
|||||||
/** Fix database consistency after import:
|
/** Fix database consistency after import:
|
||||||
* 1. Fill empty catalog_name from items_base.public_name
|
* 1. Fill empty catalog_name from items_base.public_name
|
||||||
* 2. Set have_offer = '1' where it was '0'
|
* 2. Set have_offer = '1' where it was '0'
|
||||||
* Returns { catalogNameFixed, haveOfferFixed } with counts. */
|
* 3. Set cost_credits = 3 where it was <= 0
|
||||||
|
* Returns { catalogNameFixed, haveOfferFixed, costCreditsFixed } with counts. */
|
||||||
export async function fixDatabaseConsistencyAfterImport(): Promise<{
|
export async function fixDatabaseConsistencyAfterImport(): Promise<{
|
||||||
catalogNameFixed: number;
|
catalogNameFixed: number;
|
||||||
haveOfferFixed: number;
|
haveOfferFixed: number;
|
||||||
|
costCreditsFixed: number;
|
||||||
}> {
|
}> {
|
||||||
// 1. Fill empty catalog_name from items_base.public_name
|
// 1. Fill empty catalog_name from items_base.public_name
|
||||||
const [nameResult] = (await db.execute(sql`
|
const [nameResult] = (await db.execute(sql`
|
||||||
@@ -1114,7 +1116,15 @@ export async function fixDatabaseConsistencyAfterImport(): Promise<{
|
|||||||
`)) as unknown as [Record<string, unknown>, unknown];
|
`)) as unknown as [Record<string, unknown>, unknown];
|
||||||
const haveOfferFixed = Number(offerResult.affectedRows ?? 0);
|
const haveOfferFixed = Number(offerResult.affectedRows ?? 0);
|
||||||
|
|
||||||
return { catalogNameFixed, haveOfferFixed };
|
// 3. Set cost_credits = 3 where it was <= 0
|
||||||
|
const [creditResult] = (await db.execute(sql`
|
||||||
|
UPDATE catalog_items
|
||||||
|
SET cost_credits = 3
|
||||||
|
WHERE cost_credits <= 0
|
||||||
|
`)) as unknown as [Record<string, unknown>, unknown];
|
||||||
|
const costCreditsFixed = Number(creditResult.affectedRows ?? 0);
|
||||||
|
|
||||||
|
return { catalogNameFixed, haveOfferFixed, costCreditsFixed };
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Verify and fix interaction values for ALL furniture in items_base.
|
/** Verify and fix interaction values for ALL furniture in items_base.
|
||||||
|
|||||||
Reference in new issue
Block a user