-
Notifications
You must be signed in to change notification settings - Fork 24
chore(migration): add new schemas #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jrschumacher
merged 3 commits into
policy-config-changes
from
policy-config-changes-schema
Jan 18, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS opentdf.attribute_values | ||
| ( | ||
| id UUID PRIMARY KEY, | ||
jrschumacher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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) | ||
jrschumacher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ); | ||
|
|
||
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
jrschumacher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 | ||
| } | ||
| ``` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?

There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed