-- Items can be inside other items.
--
-- Containers landed 12 August and a bag whose contents vanish at logout is not a container. Two
-- columns carry it, on both item tables:
--
--   container_slot   which item holds this one, as a SLOT KEY (see below). -1 means "nothing does",
--                    which is every row written before this migration and most rows after it.
--   container_flags  ROM's value[1] for THIS COPY -- CONT_CLOSED and CONT_LOCKED among them. A
--                    chest you closed and locked must still be closed and locked tomorrow, and that
--                    state is per-object, not per-prototype, so it cannot be read back off the
--                    template.
--
-- THE SLOT KEY, and why it is not simply a slot. Items live in two tables. `character_equipment` is
-- keyed by wear location -- slot 3 is "on your head" and always will be -- and `character_inventory`
-- is keyed by an arbitrary index. A container may be in either: a backpack you are wearing holds
-- things, and so does a sack in your pack. So a contained row needs to name a container across both
-- tables, and a bare slot number cannot.
--
-- The key is therefore: the inventory slot, or 1000 + the wear location for a worn container. 1000
-- is far above WearLocationCount and far above any plausible pack size, and CharacterMapping owns
-- the constant. Contents themselves are ALWAYS inventory rows whatever holds them, so there is one
-- place to look for them.
--
-- WHILE FIXING THIS, A LIVE BUG WAS FOUND AND FIXED IN THE MAPPING RATHER THAN HERE.
-- CharacterMapping wrote EVERY inventory row with `Slot = -1`, and slot is half the primary key --
-- so a character carrying five items saved one, the last, and lost the rest at every logout. It had
-- never been seen because every test at the mapping layer used a single item, and the round-trip
-- tests build records by hand with real slot numbers. Nothing in this file could fix that; the
-- mapping now numbers its rows. Recorded here because this is the migration whose feature depends
-- on it.
--
-- DEFAULT -1 IS UNAMBIGUOUS, unlike 0005's vnum sentinel which had to argue the case: no item is
-- ever inside slot -1, and a row written before containers existed was, correctly, inside nothing.

ALTER TABLE character_inventory ADD COLUMN container_slot  INTEGER NOT NULL DEFAULT -1;
ALTER TABLE character_inventory ADD COLUMN container_flags INTEGER NOT NULL DEFAULT 0;

ALTER TABLE character_equipment ADD COLUMN container_slot  INTEGER NOT NULL DEFAULT -1;
ALTER TABLE character_equipment ADD COLUMN container_flags INTEGER NOT NULL DEFAULT 0;
