fix: Truncation of some tables that were wrongly preserved
This commit is contained in:
@@ -511,7 +511,7 @@ PostgreSQL data lives in bind-mount directories on the host:
|
|||||||
| `./data/postgres` | Game DB (`star_wars_grid`) |
|
| `./data/postgres` | Game DB (`star_wars_grid`) |
|
||||||
| `./data/postgres_users` | Users DB (`star_wars_users`) |
|
| `./data/postgres_users` | Users DB (`star_wars_users`) |
|
||||||
|
|
||||||
A **world wipe** only cleans epoch-scoped tables when the UTC period slot changes; it does not touch the host data directories. User accounts, `user_action_quota`, `team_action_quota`, `victory_points`, and `db_metadata` survive all wipes.
|
A **world wipe** only cleans epoch-scoped tables when the UTC period slot changes; it does not touch the host data directories. Only user accounts (`users`), `victory_points`, and `db_metadata` survive all wipes. Both `user_action_quota` and `team_action_quota` are truncated and reset to config defaults on wipe.
|
||||||
|
|
||||||
To fully reset the game state (including all user accounts), stop the stack and delete both data directories, then start again:
|
To fully reset the game state (including all user accounts), stop the stack and delete both data directories, then start again:
|
||||||
|
|
||||||
|
|||||||
+7
-19
@@ -1,7 +1,7 @@
|
|||||||
import { pool } from "./pools.js";
|
import { pool } from "./pools.js";
|
||||||
import { loadConfigFile, getConfig } from "../configLoader.js";
|
import { loadConfigFile, getConfig } from "../configLoader.js";
|
||||||
import { computeWorldSeedState } from "../worldSeed.js";
|
import { computeWorldSeedState } from "../worldSeed.js";
|
||||||
import { nextResetUtc, resetAllUserActions, getUsersByIds } from "./usersDb.js";
|
import { nextResetUtc, truncateUserActionQuota, getUsersByIds } from "./usersDb.js";
|
||||||
|
|
||||||
let lastSeedSlot = null;
|
let lastSeedSlot = null;
|
||||||
|
|
||||||
@@ -94,18 +94,8 @@ export async function initGameSchema() {
|
|||||||
`);
|
`);
|
||||||
await pool.query(`
|
await pool.query(`
|
||||||
ALTER TABLE grid_cells ADD COLUMN IF NOT EXISTS discovered_by TEXT;
|
ALTER TABLE grid_cells ADD COLUMN IF NOT EXISTS discovered_by TEXT;
|
||||||
UPDATE grid_cells SET discovered_by = 'blue' WHERE discovered_by IS NULL;
|
ALTER TABLE grid_cells ALTER COLUMN discovered_by DROP NOT NULL;
|
||||||
ALTER TABLE grid_cells ALTER COLUMN discovered_by SET DEFAULT 'blue';
|
ALTER TABLE grid_cells ALTER COLUMN discovered_by SET DEFAULT NULL;
|
||||||
DO $$
|
|
||||||
BEGIN
|
|
||||||
IF NOT EXISTS (
|
|
||||||
SELECT 1 FROM pg_constraint WHERE conname = 'grid_cells_discovered_by_check'
|
|
||||||
) THEN
|
|
||||||
ALTER TABLE grid_cells ADD CONSTRAINT grid_cells_discovered_by_check
|
|
||||||
CHECK (discovered_by IN ('blue', 'red'));
|
|
||||||
END IF;
|
|
||||||
END $$;
|
|
||||||
ALTER TABLE grid_cells ALTER COLUMN discovered_by SET NOT NULL;
|
|
||||||
`);
|
`);
|
||||||
await pool.query(`
|
await pool.query(`
|
||||||
CREATE TABLE IF NOT EXISTS team_action_quota (
|
CREATE TABLE IF NOT EXISTS team_action_quota (
|
||||||
@@ -189,14 +179,12 @@ export async function ensureSeedEpoch() {
|
|||||||
const cfg = getConfig();
|
const cfg = getConfig();
|
||||||
const nextNoon = nextResetUtc(cfg.actionsResetIntervalHours ?? 12).toISOString();
|
const nextNoon = nextResetUtc(cfg.actionsResetIntervalHours ?? 12).toISOString();
|
||||||
await pool.query(
|
await pool.query(
|
||||||
`INSERT INTO team_action_quota (team, actions_remaining, quota_reset_at)
|
`TRUNCATE team_action_quota;
|
||||||
VALUES ('blue', $1, $2), ('red', $1, $2)
|
INSERT INTO team_action_quota (team, actions_remaining, quota_reset_at)
|
||||||
ON CONFLICT (team) DO UPDATE
|
VALUES ('blue', $1, $2), ('red', $1, $2)`,
|
||||||
SET actions_remaining = $1,
|
|
||||||
quota_reset_at = $2`,
|
|
||||||
[cfg.teamActionQuota, nextNoon]
|
[cfg.teamActionQuota, nextNoon]
|
||||||
);
|
);
|
||||||
await resetAllUserActions(cfg.dailyActionQuota, nextNoon);
|
await truncateUserActionQuota();
|
||||||
console.log(`[world] Slot ${lastSeedSlot} → ${seedSlot}; grid wiped, old cooldowns cleared.`);
|
console.log(`[world] Slot ${lastSeedSlot} → ${seedSlot}; grid wiped, old cooldowns cleared.`);
|
||||||
lastSeedSlot = seedSlot;
|
lastSeedSlot = seedSlot;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,3 +152,8 @@ export async function resetAllUserActions(actionsRemaining, quotaResetAt) {
|
|||||||
[actionsRemaining, quotaResetAt]
|
[actionsRemaining, quotaResetAt]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Removes all rows from user_action_quota (used on world-seed wipeout). */
|
||||||
|
export async function truncateUserActionQuota() {
|
||||||
|
await usersPool.query(`TRUNCATE user_action_quota`);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user