admin: reset-world --speed X (speed can only change on an emptied world)
Speed is stored scaled into rates and due times, so changing it under live rows would jump resources and mis-time events. reset-world now takes --speed to set the new world's speed in the same transaction. Tested: test/admin-cli.test.js (speed asserted after reset), npm test green. NOT tested beyond that. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
This commit is contained in:
parent
3c23c51902
commit
d7a27db563
3 changed files with 7 additions and 5 deletions
|
|
@ -257,7 +257,7 @@ upstream-admin replay-events --until +6h --simulate # + run the real handlers
|
||||||
upstream-admin backup /var/lib/upstream/backups --keep 14
|
upstream-admin backup /var/lib/upstream/backups --keep 14
|
||||||
upstream-admin verify-backup /var/lib/upstream/backups/upstream-20261011T041500Z.db
|
upstream-admin verify-backup /var/lib/upstream/backups/upstream-20261011T041500Z.db
|
||||||
upstream-admin grant 12 --fiber 5000 --capital 2000 --yes # testing only
|
upstream-admin grant 12 --fiber 5000 --capital 2000 --yes # testing only
|
||||||
upstream-admin reset-world 1 --yes-destroy --backup /var/lib/upstream/backups --new-seed
|
upstream-admin reset-world 1 --yes-destroy --backup /var/lib/upstream/backups --new-seed [--speed 3] # --speed is the only way to change a world's speed: it needs an emptied world
|
||||||
upstream-admin migrate # apply pending migrations without starting the server
|
upstream-admin migrate # apply pending migrations without starting the server
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -247,10 +247,11 @@ test('reset-world refuses without --yes-destroy, then wipes the world and keeps
|
||||||
assert.equal(cli(file, ['reset-world', '1', '--yes']).code, 2, '--yes is not enough for reset-world');
|
assert.equal(cli(file, ['reset-world', '1', '--yes']).code, 2, '--yes is not enough for reset-world');
|
||||||
|
|
||||||
const bk = path.join(dir, 'bk');
|
const bk = path.join(dir, 'bk');
|
||||||
const done = cli(file, ['reset-world', '1', '--yes-destroy', '--backup', bk, '--new-seed', '--json']);
|
const done = cli(file, ['reset-world', '1', '--yes-destroy', '--backup', bk, '--new-seed', '--speed', '3', '--json']);
|
||||||
assert.equal(done.code, 0, done.err);
|
assert.equal(done.code, 0, done.err);
|
||||||
const after = counts();
|
const after = counts();
|
||||||
assert.equal(after.towns, 0);
|
assert.equal(after.towns, 0);
|
||||||
|
assert.equal(cli(file, ['worlds', '--json']).out.includes('"speed": 3') || /"speed":\s*3\b/.test(cli(file, ['worlds', '--json']).out), true, '--speed sets the new world speed');
|
||||||
assert.equal(after.operators, 0);
|
assert.equal(after.operators, 0);
|
||||||
assert.equal(after.buildings, 0);
|
assert.equal(after.buildings, 0);
|
||||||
assert.equal(after.users, 1, 'accounts are kept');
|
assert.equal(after.users, 1, 'accounts are kept');
|
||||||
|
|
|
||||||
|
|
@ -658,17 +658,18 @@ commands['reset-world'] = (args, ctx) => {
|
||||||
if (args.flags.backup) backup = doBackup(db, path.resolve(ctx.cwd, args.flags.backup), now, {});
|
if (args.flags.backup) backup = doBackup(db, path.resolve(ctx.cwd, args.flags.backup), now, {});
|
||||||
const newSeed = args.flags.seed !== undefined ? intFlag(args.flags, 'seed', { min: 1, max: 2 ** 31 - 1 })
|
const newSeed = args.flags.seed !== undefined ? intFlag(args.flags, 'seed', { min: 1, max: 2 ** 31 - 1 })
|
||||||
: args.flags['new-seed'] ? require('crypto').randomInt(1, 2 ** 31 - 1) : null;
|
: args.flags['new-seed'] ? require('crypto').randomInt(1, 2 ** 31 - 1) : null;
|
||||||
|
const newSpeed = numFlag(args.flags, 'speed', { min: 0.1, max: 100, def: undefined }); // speed cannot change under live rows (rates, due times are stored scaled): only on an emptied world
|
||||||
db.exec('PRAGMA foreign_keys = OFF'); // children are deleted first, but later stages may add odd tables
|
db.exec('PRAGMA foreign_keys = OFF'); // children are deleted first, but later stages may add odd tables
|
||||||
try {
|
try {
|
||||||
db.tx(() => {
|
db.tx(() => {
|
||||||
if (tableExists(db, 'idempotency')) db.run('DELETE FROM idempotency WHERE user_id IN (SELECT user_id FROM operators WHERE world_id = ?)', id);
|
if (tableExists(db, 'idempotency')) db.run('DELETE FROM idempotency WHERE user_id IN (SELECT user_id FROM operators WHERE world_id = ?)', id);
|
||||||
for (const s of plan.steps) db.run('DELETE FROM ' + s.table + ' WHERE ' + s.scope.sql, ...s.scope.params);
|
for (const s of plan.steps) db.run('DELETE FROM ' + s.table + ' WHERE ' + s.scope.sql, ...s.scope.params);
|
||||||
db.run("UPDATE worlds SET start_at = ?, end_at = NULL, status = 'running'" + (newSeed ? ', seed = ?' : '') + ' WHERE id = ?', now, ...(newSeed ? [newSeed] : []), id);
|
db.run("UPDATE worlds SET start_at = ?, end_at = NULL, status = 'running'" + (newSeed ? ', seed = ?' : '') + (newSpeed !== undefined ? ', speed = ?' : '') + ' WHERE id = ?', now, ...(newSeed ? [newSeed] : []), ...(newSpeed !== undefined ? [newSpeed] : []), id);
|
||||||
const bad = db.all('PRAGMA foreign_key_check');
|
const bad = db.all('PRAGMA foreign_key_check');
|
||||||
if (bad.length) throw new AdminError('reset would leave dangling references (' + bad.length + ', first in table ' + bad[0].table + '): rolled back');
|
if (bad.length) throw new AdminError('reset would leave dangling references (' + bad.length + ', first in table ' + bad[0].table + '): rolled back');
|
||||||
});
|
});
|
||||||
} finally { db.exec('PRAGMA foreign_keys = ON'); }
|
} finally { db.exec('PRAGMA foreign_keys = ON'); }
|
||||||
const lines = ['world ' + id + ' reset (running again, start ' + iso(now) + (newSeed ? ', new seed ' + newSeed : ', same seed') + '). Deleted:', ...summary,
|
const lines = ['world ' + id + ' reset (running again, start ' + iso(now) + (newSeed ? ', new seed ' + newSeed : ', same seed') + (newSpeed !== undefined ? ', speed ' + newSpeed : '') + '). Deleted:', ...summary,
|
||||||
'Accounts were kept; players must join the world again.'];
|
'Accounts were kept; players must join the world again.'];
|
||||||
if (backup) lines.push('backup before reset: ' + backup.file);
|
if (backup) lines.push('backup before reset: ' + backup.file);
|
||||||
return { data: { id, deleted: counts, seed: newSeed, backup: backup && backup.file }, lines };
|
return { data: { id, deleted: counts, seed: newSeed, backup: backup && backup.file }, lines };
|
||||||
|
|
@ -719,7 +720,7 @@ const HELP_CMDS = {
|
||||||
'replay-events': '[--until now|+2h|ISO] [--world ID] [--limit N] [--simulate] dry run: what the scheduler would process; --simulate runs the handlers on a scratch copy',
|
'replay-events': '[--until now|+2h|ISO] [--world ID] [--limit N] [--simulate] dry run: what the scheduler would process; --simulate runs the handlers on a scratch copy',
|
||||||
backup: '<dest-dir> [--keep N] [--keep-days D] consistent VACUUM INTO snapshot, verified, never overwrites; prunes old ones',
|
backup: '<dest-dir> [--keep N] [--keep-days D] consistent VACUUM INTO snapshot, verified, never overwrites; prunes old ones',
|
||||||
'verify-backup': '<file> integrity check of a snapshot (read-only)',
|
'verify-backup': '<file> integrity check of a snapshot (read-only)',
|
||||||
'reset-world': '<world-id> --yes-destroy [--backup DIR] [--seed S | --new-seed] delete that world\'s game rows, keep accounts',
|
'reset-world': '<world-id> --yes-destroy [--backup DIR] [--seed S | --new-seed] [--speed X] delete that world\'s game rows, keep accounts (--speed sets the new world speed)',
|
||||||
grant: '<town-id> --yes [--fiber N] [--hardware N] [--capital N] [--battery N] [--all N] add resources (testing)',
|
grant: '<town-id> --yes [--fiber N] [--hardware N] [--capital N] [--battery N] [--all N] add resources (testing)',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue