-
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
Merged
Changes from 9 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
24 changes: 24 additions & 0 deletions
24
service/policy/db/migrations/20250407000000_add_registered_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,24 @@ | ||
| # Add Non Data Resources Table | ||
| [ADR for Non Data Resource Support](https://github.com/opentdf/platform/issues/1915) | ||
| ```mermaid | ||
| erDiagram | ||
| registered_resources ||--o{ registered_resource_values : "has" | ||
|
|
||
| registered_resources { | ||
| UUID id PK | ||
ryanulit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| VARCHAR name "NOT NULL, UNIQUE" | ||
ryanulit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| JSONB metadata | ||
ryanulit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| TIMESTAMP_WITH_TZ created_at "NOT NULL, DEFAULT CURRENT_TIMESTAMP" | ||
| TIMESTAMP_WITH_TZ updated_at "NOT NULL, DEFAULT CURRENT_TIMESTAMP" | ||
| } | ||
|
|
||
| registered_resource_values { | ||
| UUID id PK | ||
ryanulit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| UUID registered_resource_id FK "NOT NULL, REFERENCES registered_resources(id)" | ||
| VARCHAR value | ||
ryanulit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| JSONB metadata | ||
ryanulit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| TIMESTAMP_WITH_TZ created_at "NOT NULL, DEFAULT CURRENT_TIMESTAMP" | ||
| TIMESTAMP_WITH_TZ updated_at "NOT NULL, DEFAULT CURRENT_TIMESTAMP" | ||
| CONSTRAINT unique_resource_value "UNIQUE(registered_resource_id, value)" | ||
| } | ||
| ``` | ||
56 changes: 56 additions & 0 deletions
56
service/policy/db/migrations/20250407000000_add_registered_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,56 @@ | ||
| -- +goose Up | ||
| -- +goose StatementBegin | ||
|
|
||
| CREATE TABLE IF NOT EXISTS registered_resources ( | ||
| id UUID PRIMARY KEY DEFAULT gen_random_uuid(), | ||
| name VARCHAR NOT NULL UNIQUE, | ||
| metadata JSONB, | ||
| 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 registered_resources IS 'Table to store registered resources'; | ||
| COMMENT ON COLUMN registered_resources.id IS 'Primary key for the table'; | ||
| COMMENT ON COLUMN registered_resources.name IS 'Name for the registered resource'; | ||
| COMMENT ON COLUMN registered_resources.metadata IS 'Metadata for the registered resource (see protos for structure)'; | ||
| COMMENT ON COLUMN registered_resources.created_at IS 'Timestamp when the record was created'; | ||
| COMMENT ON COLUMN registered_resources.updated_at IS 'Timestamp when the record was last updated'; | ||
|
|
||
| CREATE TABLE IF NOT EXISTS registered_resource_values ( | ||
| id UUID PRIMARY KEY DEFAULT gen_random_uuid(), | ||
| registered_resource_id UUID NOT NULL REFERENCES registered_resources(id) ON DELETE CASCADE, | ||
| value VARCHAR NOT NULL, | ||
| metadata JSONB, | ||
| created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| UNIQUE(registered_resource_id, value) | ||
| ); | ||
| COMMENT ON TABLE registered_resource_values IS 'Table to store registered resource values'; | ||
| COMMENT ON COLUMN registered_resource_values.id IS 'Primary key for the table'; | ||
| COMMENT ON COLUMN registered_resource_values.registered_resource_id IS 'Foreign key to the registered_resources table'; | ||
| COMMENT ON COLUMN registered_resource_values.value IS 'Value for the registered resource value'; | ||
| COMMENT ON COLUMN registered_resource_values.metadata IS 'Metadata for the registered resource value (see protos for structure)'; | ||
| COMMENT ON COLUMN registered_resource_values.created_at IS 'Timestamp when the record was created'; | ||
| COMMENT ON COLUMN registered_resource_values.updated_at IS 'Timestamp when the record was last updated'; | ||
|
|
||
| CREATE TRIGGER registered_resources_updated_at | ||
| BEFORE UPDATE ON registered_resources | ||
| FOR EACH ROW | ||
| EXECUTE FUNCTION update_updated_at(); | ||
|
|
||
| CREATE TRIGGER registered_resource_values_updated_at | ||
| BEFORE UPDATE ON registered_resource_values | ||
| FOR EACH ROW | ||
| EXECUTE FUNCTION update_updated_at(); | ||
|
|
||
| -- +goose StatementEnd | ||
|
|
||
| -- +goose Down | ||
| -- +goose StatementBegin | ||
|
|
||
| DROP TRIGGER IF EXISTS registered_resource_values_updated_at ON registered_resource_values; | ||
| DROP TRIGGER IF EXISTS registered_resources_updated_at ON registered_resources; | ||
|
|
||
| DROP TABLE IF EXISTS registered_resource_values; | ||
| DROP TABLE IF EXISTS registered_resources; | ||
|
|
||
| -- +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.