feat: expand profiles and weapon configuration
Validate and deploy production / validate (push) Successful in 26s
Validate and deploy staging / validate (push) Successful in 25s
Validate and deploy production / deploy (push) Failing after 1m10s
Validate and deploy staging / deploy (push) Failing after 8s

This commit is contained in:
JB
2026-07-28 00:11:40 -04:00
parent 0b3be3587b
commit a434cbe60c
37 changed files with 2209 additions and 800 deletions
+48
View File
@@ -2,6 +2,7 @@ import { connect } from '@tursodatabase/database';
import { access, mkdir, readFile } from 'node:fs/promises';
import { dirname, resolve } from 'node:path';
import process from 'node:process';
import { randomUUID } from 'node:crypto';
import { initializeDefaultUsers } from './default-users.mjs';
const gearSlots = ['Holster', 'Gloves', 'Backpack', 'Knee Pads', 'Body Armor', 'Mask'];
@@ -386,6 +387,53 @@ for (const statement of statements) {
await database.exec(statement);
}
const weaponBonusAttributes = await (
await database.prepare(`SELECT id,name FROM stat_attributes
WHERE name IN ('Weapon Critical Hit Chance','Weapon Critical Hit Damage','Headshot Damage')`)
).all();
if (weaponBonusAttributes.length && weaponBonusAttributes.length !== 3) {
throw new Error('The shared weapon-category bonus migration requires all three fixed weapon Attributes.');
}
if (weaponBonusAttributes.length === 3) {
const attributeId = (name) => String(weaponBonusAttributes.find((attribute) => attribute.name === name)?.id ?? '');
const defaults = [
['Weapon Critical Hit Chance', 5],
['Weapon Critical Hit Damage', 50],
['Headshot Damage', 40]
];
await database.exec('BEGIN');
try {
for (const category of ['Shotgun', 'Rifle', 'MMR', 'AR', 'LMG', 'SMG']) {
for (let index = 0; index < defaults.length; index += 1) {
const [name, defaultValue] = defaults[index];
const value = category === 'MMR' && name === 'Headshot Damage' ? 70 : defaultValue;
await (await database.prepare(`INSERT OR IGNORE INTO weapon_category_attribute_bonuses(
id,weapon_category,stat_attribute_id,value,sort_order,updated_at
) VALUES(?,?,?,?,?,?)`)).run(
randomUUID(), category, attributeId(name), value, index + 1, new Date().toISOString()
);
}
}
const configured = await (await database.prepare(
'SELECT COUNT(*) AS count FROM weapon_category_attribute_bonuses'
)).get();
if (Number(configured?.count) !== 18) {
throw new Error('Every weapon category must have exactly three shared base Attribute bonuses.');
}
const legacyWeaponBonuses = await (await database.prepare(
"SELECT 1 FROM sqlite_master WHERE type='table' AND name='weapon_base_attribute_bonuses'"
)).get();
if (legacyWeaponBonuses) {
console.log('Replacing per-weapon base Attribute bonuses with shared weapon-category profiles.');
await database.exec('DROP TABLE weapon_base_attribute_bonuses');
}
await database.exec('COMMIT');
} catch (error) {
await database.exec('ROLLBACK');
throw error;
}
}
const deletedRoleTable = await (await database.prepare(
"SELECT 1 FROM sqlite_master WHERE type='table' AND name='deleted_roles'"
)).get();