Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions migrations/20240118000000_create_new_tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
-- +goose Up
-- +goose StatementBegin
CREATE SCHEMA IF NOT EXISTS opentdf;

CREATE TYPE attribute_definition_rule AS ENUM ('UNSPECIFIED', 'ALL_OF', 'ANY_OF', 'HIERARCHY');
CREATE TYPE subject_mappings_operator AS ENUM ('UNSPECIFIED', 'IN', 'NOT_IN');

CREATE TABLE IF NOT EXISTS opentdf.namespaces
(
id UUID PRIMARY KEY,
name VARCHAR NOT NULL UNIQUE
);

CREATE TABLE IF NOT EXISTS opentdf.attribute_definitions
(
id UUID PRIMARY KEY,
namespace_id UUID NOT NULL REFERENCES opentdf.namespaces(id),
name VARCHAR NOT NULL,
rule attribute_definition_rule NOT NULL,
metadata JSONB,
UNIQUE (namespace_id, name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the namespace_id + attribute value, or the namespace_id + attribute name?
Screenshot 2024-01-18 at 2 17 56 PM

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ERD is wrong in this case

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

);

CREATE TABLE IF NOT EXISTS opentdf.attribute_values
(
id UUID PRIMARY KEY,
attribute_definition_id UUID NOT NULL REFERENCES opentdf.attribute_definitions(id),
value VARCHAR NOT NULL,
members UUID[] NOT NULL,
metadata JSONB,
UNIQUE (attribute_definition_id, value)
);

CREATE TABLE IF NOT EXISTS opentdf.key_access_servers
(
id UUID PRIMARY KEY,
key_access_server VARCHAR NOT NULL UNIQUE,
public_key VARCHAR NOT NULL,
metadata JSONB
);

CREATE TABLE IF NOT EXISTS opentdf.attribute_definition_key_access_grants
(
attribute_definition_id UUID NOT NULL REFERENCES opentdf.attribute_definitions(id),
key_access_server_id UUID NOT NULL REFERENCES opentdf.key_access_servers(id),
PRIMARY KEY (attribute_definition_id, key_access_server_id)
);

CREATE TABLE IF NOT EXISTS opentdf.attribute_value_key_access_grants
(
attribute_value_id UUID NOT NULL REFERENCES opentdf.attribute_values(id),
key_access_server_id UUID NOT NULL REFERENCES opentdf.key_access_servers(id),
PRIMARY KEY (attribute_value_id, key_access_server_id)
);

CREATE TABLE IF NOT EXISTS opentdf.resource_mappings
(
id UUID PRIMARY KEY,
attribute_value_id UUID NOT NULL REFERENCES opentdf.attribute_values(id),
name VARCHAR NOT NULL,
terms VARCHAR[],
metadata JSONB
);

CREATE TABLE IF NOT EXISTS opentdf.subject_mappings
(
id UUID PRIMARY KEY,
attribute_value_id UUID NOT NULL REFERENCES opentdf.attribute_values(id),
operator subject_mappings_operator NOT NULL,
subject_attribute VARCHAR NOT NULL,
subject_attribute_values VARCHAR[],
metadata JSONB
);
-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
DROP TABLE IF EXISTS opentdf.key_access_servers;
DROP TABLE IF EXISTS opentdf.subject_mappings;
DROP TABLE IF EXISTS opentdf.resource_mappings;
DROP TABLE IF EXISTS opentdf.attribute_value_key_access_grants;
DROP TABLE IF EXISTS opentdf.attribute_definition_key_access_grants;
DROP TABLE IF EXISTS opentdf.attribute_values;
DROP TABLE IF EXISTS opentdf.attribute_definitions;
DROP TABLE IF EXISTS opentdf.namespaces;

DELETE TYPE attribute_definition_rule;
DELETE TYPE subject_mappings_operator;
-- +goose StatementEnd
89 changes: 89 additions & 0 deletions migrations/20240118000000_diagram.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Diagram for 20240118000000_create_new_tables.sql

```mermaid
---
title: Database Schema Mermaid Diagram
nodes: |
Metadata is a jsonb type which will hold a common structure

To note OCI data we can utilize labels (i.e. map[string]string)
"labels": {
"oci:version": "1.0.0"
"oci:...": "..."
}

---

erDiagram

Namespace ||--|{ AttributeDefinition : has
AttributeDefinition ||--|{ AttributeValue : has
AttributeDefinition ||--o{ AttributeDefinitionKeyAccessGrant : has

AttributeValue ||--o{ AttributeValueKeyAccessGrant: has
AttributeValue ||--o{ AttributeValue: "has group members"

AttributeDefinitionKeyAccessGrant ||--|{ KeyAccessServer: has
AttributeValueKeyAccessGrant ||--|{ KeyAccessServer: has

ResourceMapping }o--o{ AttributeValue: relates

SubjectMapping }o--o{ AttributeValue: relates

Namespace {
uuid id PK
varchar name UK
}

AttributeDefinition {
uuid id PK
uuid namespace_id FK
varchar name
enum rule
jsonb metadata
compIdx comp_key UK "ns_id + name"
}

AttributeDefinitionKeyAccessGrant {
uuid attribute_definition_id FK
uuid key_access_server_id FK
}

AttributeValue {
uuid namespace_id FK
uuid attribute_definition_id FK
varchar value
uuid[] members FK "Optional grouping of values"
jsonb metadata
compIdx comp_key UK "ns_id + ad_id + value"
}

AttributeValueKeyAccessGrant {
uuid attribute_value_id FK
uuid key_access_server_id FK
}

ResourceMapping {
uuid id PK
uuid attribute_value_id FK
varchar name
varchar[] terms
jsonb metadata
}

SubjectMapping {
uuid id PK
uuid attribute_value_id
enum operator
varchar subject_attribute
varchar[] subject_attribute_values
jsonb metadata
}

KeyAccessServer {
uuid id PK
varchar key_access_server UK
varchar public_key
jsonb metadata
}
```