Content and Migrations
Where the world lives
Items, node types, creatures, recipes, skills and the things standing in the world are rows in the database, not a file. That is not a preference — a GM who places a tree in-game cannot write into a container image, and editing a file would need a rebuild and a restart before anyone could use the thing they placed.
What is left in files is the terrain: enormous, static, and worth having in version control. That is the shape of the split — anything a person changes while the game is running is a row; anything nobody changes at runtime is a file.
The cost is real and worth naming: world content is no longer in git. A new
item type is a row, not a diff. You lose review, blame, and the ability to hand
someone a branch of the world. The live database is covered by
backup-postgres.sh.
Content is seeded, placement is not
Content that the game needs everywhere — items, materials, skills, node types, creatures, recipes — is added by the migration that introduces it. A fresh database built from migrations has a usable catalogue the moment it is migrated.
Things standing in the world are mostly placed, not seeded. A node type is content, a node is placement, and placement happens in-game through the GM panel. Seeding node positions would put a thing in the world that nobody in the world put there. So a fresh database has all the sources and materials but no Tree, Flint Deposit, Copper Vein or Flax Field.
The checks assert against sources and materials, so they pass on a database that has never had a GM in it.
The exceptions are a few placed things that a feature cannot work without, such as the slime, owl and crow spawners, which their migrations place at fixed positions. Migrations that change an existing placed thing, such as Anyxa, find it by name.
The largest exception is the forest round the village: 400 trees that
TallTreesAndForest seeds in groves in a ring up to ~250 m out from the
village's clear rectangle (x -100..200, z -185..150), never in the lake or on
ground below 0 m. Conifers (Scots Pine, Spruce) stand on the higher ground,
broadleaves (Oak, Beech, Birch, Maple) lower down, and a few yews among them.
scripts/plant_forest.py made the rows from a fixed seed, sampling the
server's own terrain with scripts/sample_terrain_heights.gd in the dev game
server container; the migration carries the rows, heights included, so it
applies without any terrain. To regrow it (after the terrain changes, say),
rerun the script and replace the migration's Forest list in a new migration.
Writing a content migration
Content goes in as SQL, not HasData
Content additions go in as explicit SQL in the migration that introduces them,
not through HasData. EF rebuilds a seeded table whenever its rows change on a
table something else points at: it drops the constraints, renames the table,
recreates it, and reinserts. The rebuild re-emits columns from the CLR type, so a
HasConversion<string>() is silently lost and the migration then tries to cast
'Craft' to an integer and stops halfway.
It also emits the dependent table's seed updates before the rows they reference, so a node type can name a skill that has not been inserted yet.
Both happened, and the second one only showed up as a foreign key violation in the middle of an otherwise clean apply.
The rule that comes out of it: content goes in as SQL in dependency order — materials, then their lore skills, then the sources that name both. The reference rows the very first migration created stay as they are so history is not rewritten.
Many newer columns (on recipes, crafting jobs, creatures) are read and written by SQL only and have no EF property. The migration's summary comment says so.
Write the migration so it does not overwrite an admin's edits. For example,
SpawnerModels sets a spawner type's ModelPath only where it is still empty,
and its Down clears only what it set.
Solid models
The game server never loads the client's scenes. It builds a solid node's
collider from node_types.Collision: a JSON array with one entry per
CollisionShape3D in the model's scene, in the format
godot_client/scripts/export_world_collisions.gd writes (type, its size,
transform and disabled). '[]' is walked through. The server reads the
column whenever it reloads the world, so new shapes take effect without a
restart.
To add a solid model:
- Give it a
.tscnwith aStaticBody3Dand its collision shape. - Write a migration that sets the node type's
ModelPathto that scene and itsCollisionto the same shape. Run the exporter to get the JSON:godot --headless --path godot_client --script res://scripts/export_world_collisions.gd -- out.json. - Run
python scripts/check_collisions.py, which exports every scene in the dev game server container and fails if any node type'sCollisiondiffers from its scene.
Resizing a collider in a .tscn also needs a migration, and the check catches a
forgotten one. NodeTypeCollision added the column and set the ten scenes that
existed then.
Model variants
A node type's ModelPath may list several scenes separated by |, the same
thing in different shapes. The seven trees (Oak Tree, Scots Pine, Maple Tree,
Yew Tree, Beech Tree, Spruce Tree, Birch Tree) list five each,
scenes/resource_nodes/<key>_1.tscn to <key>_5.tscn, each wrapping
models/trees/<key>_<n>.gltf.
- Each world entity wears one:
world_entities.Variantcounts from 1 into the list (oak_tree_3.tscnis variant 3). The server resolves it when it loads the world (ServerMain.PickModelPath) and sends the client only that one path, so the client knows nothing about variants. - A row with no
Variant(one from before its type had variants) wears entryId % count: steady across reloads, never written back. A value past the end of the list wraps. - A GM placing such a type gets a random variant, saved with the row. The GM panel's catalogue is sent the first entry.
- All variants of a type share its one
Collision, since the server builds one collider per type: give every variant scene the same shape.check_collisions.pychecks each listed scene against it. - The admin panel's node type page accepts a
|list, each entry checked as a model path.
The migration boundary is the last applied one
dotnet ef migrations script <from> <to> re-runs every migration after <from>.
The boundary has to be the last migration in __EFMigrationsHistory, not the last
one on disk, and getting it wrong does not fail loudly.
It once applied a migration that wiped node_type_yields and re-inserted six rows
— the maple row, added by hand because it belonged to a migration not yet
written, was gone and its gate with it. The failure surfaced two checks later as
a maple tree that refused nobody and a lore skill that never unlocked, which looks
nothing like the cause.
The rule: generate from the last applied migration, and treat a clean apply as evidence rather than proof — the script that wipes and re-inserts a table is indistinguishable from one that merely adds a column until something reads the row afterwards.
Back up before a migration that changes content. Several migrations note the
dump taken before they were applied, under replay/ (ignored by Git).
The admin panel cannot delete a material
An item is held open by three things: inventory rows, node types that yield it, and the lore skill whose subject it is. That third one arrived with tier 1, and until the panel knew about it, deleting Flint returned a bare 500 from the foreign key — the refusal was happening, it just arrived as a crash.
Worse, and older: the Error on that page was [BindProperty], so it was empty
on the GET that a redirect lands on. Every refusal message on the page had been
silently discarded. The delete was refused and no sentence ever appeared, which
looks exactly like the panel having done nothing. It is [TempData] now.