Files
SGF/scripts/sgf-workshop-equipment-schema.php
T
2026-11-11 09:00:17 +02:00

3 lines
1.3 KiB
PHP

<?php
$book=$argv[1]??'regression';require __DIR__.'/sgf-single-bootstrap.php';if(!$host->getSchemaBuilder()->hasTable('wo_equipment_commands'))$host->transaction(function()use($host){$host->unprepared('CREATE TABLE wo_equipment_commands(id bigserial PRIMARY KEY,tenant_id bigint NOT NULL,company_id bigint NOT NULL,unit_id bigint NOT NULL,actor_id bigint NOT NULL REFERENCES users(id),command_key uuid NOT NULL,request_hash char(64) NOT NULL,equipment_id bigint NOT NULL UNIQUE REFERENCES wo_equipment(id),reason text NOT NULL CHECK(length(reason)>=10),created_at timestamptz NOT NULL,UNIQUE(tenant_id,company_id,unit_id,actor_id,command_key),FOREIGN KEY(tenant_id,company_id,unit_id) REFERENCES units(tenant_id,company_id,id))');$host->unprepared('CREATE TRIGGER wo_equipment_command_immutable BEFORE UPDATE OR DELETE ON wo_equipment_commands FOR EACH ROW EXECUTE FUNCTION sgf_append_only_audit()');$host->unprepared('CREATE TRIGGER wo_equipment_command_testing BEFORE INSERT ON wo_equipment_commands FOR EACH ROW EXECUTE FUNCTION sgf_wo_test_only()');$host->statement('REVOKE ALL ON TABLE wo_equipment_commands FROM PUBLIC');$host->statement('REVOKE ALL ON SEQUENCE wo_equipment_commands_id_seq FROM PUBLIC');});echo json_encode(['passed'=>true,'book'=>$book,'business_commands'=>0,'new_rights'=>0]).PHP_EOL;