Files
Module-uo/server/db/purge.sql
wtclaude f7bb3d912e fix(db): own the two settings seeds, and repair the protocol-3 one-shot
Core seeded `game_account_signup` and `uo_link_protocol_3_migrated`, two keys
that name a game concept. That made core's schema declare a module's settings,
which is the structural half of what Phase 3 removes (MODULE_SYSTEM.md §2.7.1,
slice 4). Both INSERTs move here. The keys are deliberately unchanged: they are
live rows on every existing install and renaming one silently resets an
operator's choice to the default.

The marker is not just a tidy-up. It and the `UPDATE uo_link_config SET
protocol = 3` it makes one-shot were adjacent in core's schema.sql until slice 1
moved the UPDATE here and left the INSERT behind — and the two files do not run
together: core's schema is replayed in full before any module fragment. So the
marker existed before the UPDATE ever read it, the NOT EXISTS guard was false on
every boot of an upgraded install, and the migration could never fire. An
install carrying a protocol-2 row would have stayed pinned at 2 against a v3
sidecar, 409ing every REST call — the exact failure the migration prevents.
Latent rather than live: it bites only an install that first boots a
post-slice-1 build while already holding a uo_link_config row, and `edge` has
not cut over.

`schemaFragment.test.js` asserts the order, plus the fragment rules core
validates at load time (leading-verb allowlist, IF NOT EXISTS, grandfathered
table prefixes) — restated here for the same reason manifest.test.js restates
the manifest rules. Its statement splitter is a character walk, because a
comment in this file contains quotes.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-11 21:27:52 -05:00

57 lines
2.9 KiB
SQL

-- ── module-uo's teardown ──────────────────────────────────────────────────
--
-- Destructive, and run ONLY by an explicit admin purge (MODULE_API.md §2.6).
-- Nothing on the boot path ever executes this file — uninstalling a module
-- leaves its data alone, and removing the data is a separate decision an
-- operator has to make on purpose.
--
-- It exists because `schema.sql` does. A module that can create tables and
-- cannot drop them leaves an operator with orphaned data and no supported way
-- to remove it, which is why core refuses to load a module that declares one
-- without the other.
--
-- **The order is the reverse of creation, and that is load-bearing**: two of
-- these tables carry a foreign key into core's `users`, and several reference
-- each other. Dropping a parent before its children fails on the constraint,
-- and a purge that fails halfway is worse than one that does not run — it
-- leaves exactly the orphaned data this file exists to remove. `IF EXISTS` on
-- every line so a partially-installed module still tears down cleanly.
--
-- What is NOT here, deliberately: rows this module wrote into core's tables.
-- `notification_subs` rows for `shard.*` streams and `announce_job_legs` rows
-- with leg `towncrier` belong to core's tables, and a module does not delete
-- from those — core prunes them when it drops the registrations, which it can
-- do because it knows which registrant owned what. The two `settings` rows
-- schema.sql seeds (`game_account_signup`, `uo_link_protocol_3_migrated`) are
-- the same case with an extra reason: the second is a one-shot MIGRATION
-- marker, and deleting it would re-arm a protocol bump against tables this
-- file has just dropped.
DROP TABLE IF EXISTS `shard_atlas_pending`;
DROP TABLE IF EXISTS `shard_atlas_meta`;
DROP TABLE IF EXISTS `shard_cliloc_meta`;
DROP TABLE IF EXISTS `shard_clilocs`;
DROP TABLE IF EXISTS `shard_champion_spawns`;
DROP TABLE IF EXISTS `shard_landmarks`;
DROP TABLE IF EXISTS `shard_regions`;
DROP TABLE IF EXISTS `shard_spawn_point_types`;
DROP TABLE IF EXISTS `shard_spawn_points`;
DROP TABLE IF EXISTS `shard_spawn_creatures`;
DROP TABLE IF EXISTS `shard_feature_visibility`;
DROP TABLE IF EXISTS `shard_vendor_items`;
DROP TABLE IF EXISTS `shard_vendors`;
DROP TABLE IF EXISTS `shard_points_boards`;
DROP TABLE IF EXISTS `shard_ruleset`;
DROP TABLE IF EXISTS `shard_presence`;
DROP TABLE IF EXISTS `shard_governor_terms`;
DROP TABLE IF EXISTS `shard_governors`;
DROP TABLE IF EXISTS `shard_guilds`;
DROP TABLE IF EXISTS `shard_pages`;
DROP TABLE IF EXISTS `shard_champs`;
DROP TABLE IF EXISTS `shard_account_links`;
DROP TABLE IF EXISTS `shard_houses`;
DROP TABLE IF EXISTS `shard_economy`;
DROP TABLE IF EXISTS `shard_online`;
DROP TABLE IF EXISTS `shard_events`;
DROP TABLE IF EXISTS `uo_link_config`;