-- Admin take and cull (ADR-0182 section 16, 2026-10-28). Two more admin command kinds for -- testing a live region: take_reserve (8) moves up to the given amounts from one life's -- reserve to the spent pool, the inverse of grant_reserve; remove_wildlife (9) removes every -- life without an account at once, as remove_cell does one. ALTER TABLE evolution.admin_commands DROP CONSTRAINT admin_commands_kind_check; ALTER TABLE evolution.admin_commands ADD CONSTRAINT admin_commands_kind_check CHECK (kind BETWEEN 1 AND 9); -- Queues a command (the same shapes the owner accepts). Spawning takes its identities from the -- world's life allocator, so they never meet a player's. CREATE OR REPLACE FUNCTION evolution.admin_enqueue_command_v1(p_world evolution.u64, p_region evolution.u64, p_kind integer, p_count integer, p_target evolution.u64, p_energy evolution.u64, p_carbon evolution.u64, p_nitrogen evolution.u64, p_phosphorus evolution.u64, p_other evolution.u64, p_subject text, p_reason text) RETURNS TABLE (command_id bigint, target evolution.u64) LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog, pg_temp AS $$ #variable_conflict use_column DECLARE has_amount boolean := p_energy + p_carbon + p_nitrogen + p_phosphorus + p_other > 0; first numeric := p_target; BEGIN IF NOT ((p_kind IN (1, 2, 8) AND p_target > 0 AND p_count = 0 AND has_amount = (p_kind IN (2, 8))) OR (p_kind IN (3, 5) AND p_target = 0 AND p_count BETWEEN 1 AND 256 AND has_amount) OR (p_kind = 4 AND p_target = 0 AND p_count = 0 AND has_amount) OR (p_kind = 6 AND p_count BETWEEN 1 AND 64 AND NOT has_amount) OR (p_kind = 9 AND p_target = 0 AND p_count = 0 AND NOT has_amount)) THEN RAISE EXCEPTION 'invalid admin command' USING ERRCODE = '22023'; END IF; IF NOT EXISTS (SELECT 1 FROM evolution.region_leases l WHERE l.world_id = p_world AND l.region_id = p_region) THEN RAISE EXCEPTION 'unknown region' USING ERRCODE = '22023'; END IF; IF p_kind = 6 THEN SELECT a.next_identity INTO first FROM evolution.life_allocators a WHERE a.world_id = p_world FOR UPDATE; IF first IS NULL OR first + p_count > 9223372036854775808 THEN RAISE EXCEPTION 'no identities for wildlife' USING ERRCODE = '22023'; END IF; UPDATE evolution.life_allocators SET next_identity = first + p_count WHERE world_id = p_world; END IF; RETURN QUERY WITH queued AS ( INSERT INTO evolution.admin_commands AS q(world_id, region_id, kind, cell_count, target, energy, carbon, nitrogen, phosphorus, other, author_subject, reason) VALUES (p_world, p_region, p_kind, p_count, first, p_energy, p_carbon, p_nitrogen, p_phosphorus, p_other, p_subject, coalesce(p_reason, '')) RETURNING q.command_id, q.target) SELECT queued.command_id, queued.target FROM queued; END $$; INSERT INTO evolution.schema_migrations(version,sha256) VALUES(67,:'migration_sha_67');