|  | 
|  | 1 | +-- +goose Up | 
|  | 2 | +-- +goose StatementBegin | 
|  | 3 | + | 
|  | 4 | +CREATE TABLE IF NOT EXISTS obligation_definitions | 
|  | 5 | +( | 
|  | 6 | +    id UUID PRIMARY KEY DEFAULT gen_random_uuid(), | 
|  | 7 | +    namespace_id UUID NOT NULL REFERENCES attribute_namespaces(id) ON DELETE CASCADE, | 
|  | 8 | +    -- name is a unique identifier for the obligation definition within the namespace | 
|  | 9 | +    name VARCHAR NOT NULL, | 
|  | 10 | +    metadata JSONB, | 
|  | 11 | +    created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, | 
|  | 12 | +    updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, | 
|  | 13 | +    -- implicit index on unique (namespace_id, name) combo | 
|  | 14 | +    -- index name: obligation_definitions_namespace_id_name_key | 
|  | 15 | +    UNIQUE (namespace_id, name) | 
|  | 16 | +); | 
|  | 17 | + | 
|  | 18 | +CREATE TABLE IF NOT EXISTS obligation_values_standard | 
|  | 19 | +( | 
|  | 20 | +    id UUID PRIMARY KEY DEFAULT gen_random_uuid(), | 
|  | 21 | +    obligation_definition_id UUID NOT NULL REFERENCES obligation_definitions(id) ON DELETE CASCADE, | 
|  | 22 | +    -- value is a unique identifier for the obligation value within the definition | 
|  | 23 | +    value VARCHAR NOT NULL, | 
|  | 24 | +    metadata JSONB, | 
|  | 25 | +    created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, | 
|  | 26 | +    updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, | 
|  | 27 | +    -- implicit index on unique (obligation_definition_id, value) combo | 
|  | 28 | +    -- index name: obligation_values_standard_obligation_definition_id_value_key | 
|  | 29 | +    UNIQUE (obligation_definition_id, value) | 
|  | 30 | +); | 
|  | 31 | + | 
|  | 32 | +CREATE TABLE IF NOT EXISTS obligation_triggers | 
|  | 33 | +( | 
|  | 34 | +    id UUID PRIMARY KEY DEFAULT gen_random_uuid(), | 
|  | 35 | +    obligation_value_id UUID NOT NULL REFERENCES obligation_values_standard(id) ON DELETE CASCADE, | 
|  | 36 | +    action_id UUID NOT NULL REFERENCES actions(id) ON DELETE CASCADE, | 
|  | 37 | +    attribute_value_id UUID NOT NULL REFERENCES attribute_values(id) ON DELETE CASCADE, | 
|  | 38 | +    metadata JSONB, | 
|  | 39 | +    created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, | 
|  | 40 | +    updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, | 
|  | 41 | +    UNIQUE(obligation_value_id, action_id, attribute_value_id) | 
|  | 42 | +); | 
|  | 43 | + | 
|  | 44 | +CREATE TABLE IF NOT EXISTS obligation_fulfillers | 
|  | 45 | +( | 
|  | 46 | +    id UUID PRIMARY KEY DEFAULT gen_random_uuid(), | 
|  | 47 | +    obligation_value_id UUID NOT NULL REFERENCES obligation_values_standard(id) ON DELETE CASCADE, | 
|  | 48 | +    conditionals JSONB, | 
|  | 49 | +    metadata JSONB, | 
|  | 50 | +    created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, | 
|  | 51 | +    updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP | 
|  | 52 | +); | 
|  | 53 | + | 
|  | 54 | +CREATE TRIGGER obligation_definitions_updated_at | 
|  | 55 | +    BEFORE UPDATE ON obligation_definitions | 
|  | 56 | +    FOR EACH ROW | 
|  | 57 | +    EXECUTE FUNCTION update_updated_at(); | 
|  | 58 | + | 
|  | 59 | +CREATE TRIGGER obligation_values_standard_updated_at | 
|  | 60 | +    BEFORE UPDATE ON obligation_values_standard | 
|  | 61 | +    FOR EACH ROW | 
|  | 62 | +    EXECUTE FUNCTION update_updated_at(); | 
|  | 63 | + | 
|  | 64 | +CREATE TRIGGER obligation_triggers_updated_at | 
|  | 65 | +    BEFORE UPDATE ON obligation_triggers | 
|  | 66 | +    FOR EACH ROW | 
|  | 67 | +    EXECUTE FUNCTION update_updated_at(); | 
|  | 68 | + | 
|  | 69 | +CREATE TRIGGER obligation_fulfillers_updated_at | 
|  | 70 | +    BEFORE UPDATE ON obligation_fulfillers | 
|  | 71 | +    FOR EACH ROW | 
|  | 72 | +    EXECUTE FUNCTION update_updated_at(); | 
|  | 73 | + | 
|  | 74 | +-- +goose StatementEnd | 
|  | 75 | + | 
|  | 76 | +-- +goose Down | 
|  | 77 | +-- +goose StatementBegin | 
|  | 78 | + | 
|  | 79 | +DROP TABLE IF EXISTS obligation_fulfillers; | 
|  | 80 | +DROP TABLE IF EXISTS obligation_triggers; | 
|  | 81 | +DROP TABLE IF EXISTS obligation_values_standard; | 
|  | 82 | +DROP TABLE IF EXISTS obligation_definitions; | 
|  | 83 | + | 
|  | 84 | +-- +goose StatementEnd | 
0 commit comments