commit melhorias sgf
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
CREATE TABLE pd_due_meta(policy text PRIMARY KEY, composition text NOT NULL, source_hash char(64) NOT NULL);
|
||||
CREATE TABLE pd_due_versions(
|
||||
id bigserial PRIMARY KEY, tenant_id bigint NOT NULL, company_id bigint NOT NULL, unit_id bigint NOT NULL,
|
||||
obligation_id bigint NOT NULL REFERENCES pa_obligations(id), version bigint NOT NULL CHECK(version>0),
|
||||
previous_id bigint UNIQUE REFERENCES pd_due_versions(id), action text NOT NULL CHECK(action IN('prepare','review')),
|
||||
state text NOT NULL CHECK(state IN('prepared','approved','refused')), source_basis char(64) NOT NULL,
|
||||
prepared_host_id bigint NOT NULL, prepared_native_id bigint NOT NULL REFERENCES users(id),
|
||||
host_actor_id bigint NOT NULL, actor_id bigint NOT NULL REFERENCES users(id), data jsonb NOT NULL,
|
||||
reason text NOT NULL CHECK(length(reason)>=10), created_at timestamptz NOT NULL,
|
||||
UNIQUE(tenant_id,company_id,unit_id,obligation_id,version),
|
||||
CHECK(jsonb_typeof(data)='object'),
|
||||
CHECK((action='prepare' AND state='prepared') OR (action='review' AND state IN('approved','refused'))),
|
||||
CHECK(action<>'review' OR (host_actor_id<>prepared_host_id AND actor_id<>prepared_native_id))
|
||||
);
|
||||
CREATE TABLE pd_due_commands(
|
||||
id bigserial PRIMARY KEY, tenant_id bigint NOT NULL, company_id bigint NOT NULL, unit_id bigint NOT NULL,
|
||||
host_actor_id bigint NOT NULL, actor_id bigint NOT NULL REFERENCES users(id), command_key uuid NOT NULL,
|
||||
request_hash char(64) NOT NULL, binding_hash char(64) NOT NULL, input jsonb NOT NULL, result jsonb NOT NULL,
|
||||
created_at timestamptz NOT NULL, UNIQUE(tenant_id,company_id,unit_id,host_actor_id,command_key)
|
||||
);
|
||||
CREATE FUNCTION pd_due_append_only() RETURNS trigger LANGUAGE plpgsql AS $$
|
||||
BEGIN RAISE EXCEPTION 'SGF_PAYABLE_DUE_APPEND_ONLY'; END; $$;
|
||||
CREATE TRIGGER pd_due_meta_immutable BEFORE UPDATE OR DELETE ON pd_due_meta FOR EACH ROW EXECUTE FUNCTION pd_due_append_only();
|
||||
CREATE TRIGGER pd_due_versions_immutable BEFORE UPDATE OR DELETE ON pd_due_versions FOR EACH ROW EXECUTE FUNCTION pd_due_append_only();
|
||||
CREATE TRIGGER pd_due_commands_immutable BEFORE UPDATE OR DELETE ON pd_due_commands FOR EACH ROW EXECUTE FUNCTION pd_due_append_only();
|
||||
Reference in New Issue
Block a user