-- M11.4c playtest gate: player-life bindings may belong to primitive or -- cellular publications. Both still reference one committed region head. ALTER TABLE evolution.primitive_life_bindings DROP CONSTRAINT primitive_life_bindings_commit_id_fkey; ALTER TABLE evolution.primitive_life_bindings ADD CONSTRAINT primitive_life_bindings_commit_id_fkey FOREIGN KEY (commit_id) REFERENCES evolution.region_commits(commit_id) DEFERRABLE INITIALLY DEFERRED; -- The binding is inserted before the cellular publication core creates its -- commit evidence, so validate the polymorphic publication link at transaction -- end. Profile-specific publishers still validate the trace and birth record. CREATE FUNCTION evolution.check_life_binding_publication() RETURNS trigger LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog, pg_temp AS $$ DECLARE profile integer; valid_publication boolean; BEGIN SELECT evolution.manifest_uint(c.manifest, 12, 4) INTO profile FROM evolution.region_commits c JOIN evolution.life_reservations r ON r.world_id = NEW.world_id AND r.account_id = NEW.account_id AND r.request_id = NEW.request_id AND r.region_id = c.region_id AND r.rejection = 0 AND r.rules = 1 WHERE c.commit_id = NEW.commit_id AND c.world_id = NEW.world_id AND c.commit_sequence > 0 AND NEW.born = evolution.manifest_uint(c.manifest, 120, 8); IF NOT FOUND THEN RAISE EXCEPTION 'life binding commit or reservation missing' USING ERRCODE = 'EVL06'; END IF; IF profile = 3 THEN SELECT EXISTS (SELECT 1 FROM evolution.primitive_publications p WHERE p.commit_id = NEW.commit_id) INTO valid_publication; ELSIF profile = 4 THEN SELECT EXISTS (SELECT 1 FROM evolution.cellular_publications p WHERE p.commit_id = NEW.commit_id) INTO valid_publication; ELSE valid_publication := false; END IF; IF NOT valid_publication THEN RAISE EXCEPTION 'life binding publication evidence missing' USING ERRCODE = 'EVL06'; END IF; RETURN NULL; END $$; REVOKE ALL ON FUNCTION evolution.check_life_binding_publication() FROM PUBLIC; CREATE CONSTRAINT TRIGGER life_binding_publication_evidence AFTER INSERT ON evolution.primitive_life_bindings DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION evolution.check_life_binding_publication(); INSERT INTO evolution.schema_migrations(version, sha256) VALUES (30, :'migration_sha_30');