Skip to content

Management Commands

Note Commands are intended for maintainers. They read and write database state and should be run in controlled environments.

Wiki ingestion and rebuild

fetch_wiki_data

⚠️ Note fetch_wiki_data only accepts true fandom.com hosts for the MediaWiki parse-API fallback. Crafted hosts that merely contain fandom.com as a substring are rejected.

Fetch and version wiki-derived data.

This command fetches selected wiki pages and versions extracted table rows into core.WikiData for later offline population steps.

Design goals: - store whitespace-normalized raw strings only, - version by deterministic content hashes (no overwrites), - support safe dry-run mode via --check, - keep parsing strict but resilient to wiki layout changes.

Command

Bases: BaseCommand

Fetch a single wiki table and store versioned rows.

This command intentionally does not feed wiki data into analysis or charts. It exists only to capture stable, attributable inputs for later phases.

add_arguments(parser)

Add command arguments.

handle(*args, **options)

Run the command.

rebuild_wiki_definitions

Rebuild wiki-derived definition tables (Definitions layer).

This command orchestrates: 1) wiki ingestion into definitions.WikiData (optional, online), then 2) offline translation into structured definition + parameter tables.

It must not delete Player State or GameData rows.

Command

Bases: BaseCommand

Rebuild Definitions and parameter tables from wiki sources.

add_arguments(parser)

Add command arguments.

handle(*args, **options)

Run the command.

purge_wiki_definitions

Purge structured wiki-derived Definitions (Definitions layer).

This command deletes only: - definition rows (bots/UWs/guardians/cards), - parameter definition rows, - parameter level rows.

It does not delete definitions.WikiData and does not touch Player State or GameData tables (though FK relationships may be nulled via SET_NULL).

Command

Bases: BaseCommand

Purge structured wiki-derived definition tables.

add_arguments(parser)

Add command arguments.

handle(*args, **options)

Run the command.

sync_player_state

Sync Player State rows from Definitions (idempotent).

Command

Bases: BaseCommand

Create/link player progress rows based on current Definitions.

add_arguments(parser)

Add command arguments.

handle(*args, **options)

Run the command.

⚠️ Note sync_player_state --player refers to a username (the owning account), not a standalone Player name. The command requires either --player or --all plus an explicit --check or --write.

Battle report maintenance

reparse_battle_reports

Reparse is idempotent and supports scoped backfills.

  • --limit processes the most recent N reports (highest ids) after any other filters.
  • --patch limits processing to the patch window that starts at the selected PatchBoundary date and ends at the next boundary date (exclusive). Provide a boundary label or ISO date.
  • Reparse also backfills bot usage rows used by Runs used on the Bots dashboard.

Reparse stored Battle Reports and backfill parsed progress fields.

Command

Bases: BaseCommand

Reparse Battle Reports and populate BattleReportProgress fields.

add_arguments(parser)

Add command arguments.

handle(*args, **options)

Run the command.

Deployment helpers

deploy_railway

Runs the deploy-time pipeline (migrations, wiki rebuild, reparse).

  • Requires --write to run.
  • --skip-migrations skips migrate.
  • --skip-wiki skips rebuild_wiki_definitions --target all --write.
  • --skip-reparse skips reparse_battle_reports --write.
  • TOWERSTATS_WIKI_OFFLINE=1 forces rebuild_wiki_definitions --skip-fetch (no network fetch).
  • TOWERSTATS_WIKI_REBUILD_TIMEOUT_SECONDS caps wiki rebuild runtime (default 300 seconds, set to 0 to disable). When exceeded, the rebuild is skipped and deploy continues.
  • Wiki rebuild failures are logged and do not abort the deploy pipeline.

Run deploy-time steps for Railway releases.

Command

Bases: BaseCommand

Run migrations and rebuild/reparse tasks for Railway deploys.

add_arguments(parser)

Add command arguments.

handle(*args, **options)

Run the deploy pipeline in order.

WikiRebuildResult dataclass

Outcome of the wiki rebuild subprocess.