-
Notifications
You must be signed in to change notification settings - Fork 24
feat(policy): DSPX-898 NDR database schema #2055
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
+98
−0
Merged
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1b95322
initial schema and mermaid diagram creation
ryanulit 4750e7c
Merge branch 'main' into DSPX-898-ndr-database-schema
ryanulit 8615804
update comments
ryanulit 8ebf2ba
add metadata column and FK cascade delete
ryanulit 8c03140
Merge branch 'main' into DSPX-898-ndr-database-schema
ryanulit 9294e6d
fix bad sql in migration
ryanulit 3d8c1a2
add unique constraint per PR comments
ryanulit 380b3a0
update mermaid diagram
ryanulit f6ac917
rename to registered resources
ryanulit 888a53e
update mermaid diagram title
ryanulit 57bd476
Merge branch 'main' into DSPX-898-ndr-database-schema
ryanulit c6ab94a
run make policy-erd-gen
ryanulit 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
21 changes: 21 additions & 0 deletions
21
service/policy/db/migrations/20250407000000_add_non_data_resources.md
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,21 @@ | ||
| # Add Non Data Resources Table | ||
| [ADR for Non Data Resource Support](https://github.com/opentdf/platform/issues/1915) | ||
| ```mermaid | ||
| erDiagram | ||
| non_data_resource_groups ||--o{ non_data_resource_values : "has" | ||
|
|
||
| non_data_resource_groups { | ||
| UUID id PK "Primary Key" | ||
| VARCHAR name "NOT NULL, UNIQUE" | ||
| TIMESTAMP created_at "NOT NULL, DEFAULT CURRENT_TIMESTAMP" | ||
| TIMESTAMP updated_at "NOT NULL, DEFAULT CURRENT_TIMESTAMP" | ||
| } | ||
|
|
||
| non_data_resource_values { | ||
| UUID id PK "Primary Key" | ||
| UUID non_data_resource_group_id FK "Foreign Key to non_data_resource_groups(id)" | ||
| VARCHAR value "NOT NULL" | ||
| TIMESTAMP created_at "NOT NULL, DEFAULT CURRENT_TIMESTAMP" | ||
| TIMESTAMP updated_at "NOT NULL, DEFAULT CURRENT_TIMESTAMP" | ||
| } | ||
| ``` |
51 changes: 51 additions & 0 deletions
51
service/policy/db/migrations/20250407000000_add_non_data_resources.sql
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,51 @@ | ||
| -- +goose Up | ||
| -- +goose StatementBegin | ||
|
|
||
| CREATE TABLE IF NOT EXISTS non_data_resource_groups ( | ||
| id UUID PRIMARY KEY DEFAULT gen_random_uuid(), | ||
| name VARCHAR NOT NULL UNIQUE, | ||
jakedoublev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP | ||
| ); | ||
| COMMENT ON TABLE non_data_resource_groups IS 'Table to store non-data resource groups'; | ||
| COMMENT ON COLUMN non_data_resource_groups.id IS 'Primary key for the table'; | ||
| COMMENT ON COLUMN non_data_resource_groups.name IS 'Name for the non-data resource group'; | ||
| COMMENT ON COLUMN non_data_resource_groups.created_at IS 'Timestamp when the record was created'; | ||
| COMMENT ON COLUMN non_data_resource_groups.updated_at IS 'Timestamp when the record was last updated'; | ||
|
|
||
| CREATE TABLE IF NOT EXISTS non_data_resource_values ( | ||
jakedoublev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| id UUID PRIMARY KEY DEFAULT gen_random_uuid(), | ||
| non_data_resource_group_id UUID NOT NULL REFERENCES non_data_resource_groups(id), | ||
| value VARCHAR NOT NULL, | ||
jakedoublev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP | ||
| ); | ||
| COMMENT ON TABLE non_data_resource_values IS 'Table to store non-data resource values'; | ||
| COMMENT ON COLUMN non_data_resource_values.id IS 'Primary key for the table'; | ||
| COMMENT ON COLUMN non_data_resource_values.non_data_resource_group_id IS 'Foreign key to the non-data resource groups table'; | ||
| COMMENT ON COLUMN non_data_resource_values.value IS 'Value for the non-data resource'; | ||
| COMMENT ON COLUMN non_data_resource_values.created_at IS 'Timestamp when the record was created'; | ||
| COMMENT ON COLUMN non_data_resource_values.updated_at IS 'Timestamp when the record was last updated'; | ||
|
|
||
| CREATE TRIGGER IF NOT EXISTS non_data_resource_groups_updated_at | ||
| BEFORE UPDATE ON non_data_resource_groups | ||
| FOR EACH ROW | ||
| EXECUTE FUNCTION update_updated_at(); | ||
|
|
||
| CREATE TRIGGER IF NOT EXISTS non_data_resource_values_updated_at | ||
| BEFORE UPDATE ON non_data_resource_values | ||
| FOR EACH ROW | ||
| EXECUTE FUNCTION update_updated_at(); | ||
|
|
||
| -- +goose StatementEnd | ||
|
|
||
| -- +goose Down | ||
| -- +goose StatementBegin | ||
|
|
||
| DROP TRIGGER IF EXISTS non_data_resource_values_updated_at ON non_data_resource_values; | ||
| DROP TRIGGER IF EXISTS non_data_resource_groups_updated_at ON non_data_resource_groups; | ||
|
|
||
| DROP TABLE IF EXISTS non_data_resource_values; | ||
| DROP TABLE IF EXISTS non_data_resource_groups; | ||
|
|
||
| -- +goose StatementEnd | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.