-
Notifications
You must be signed in to change notification settings - Fork 24
feat(policy): 1256 resource mapping groups db support #1270
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 all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e85b4b8
initial migration script
ryanulit ead6783
add delete action on FK and sqlc crud
ryanulit 4af6028
Merge branch 'main' into feat/1256-resource-mapping-groups-db-support
ryanulit c19cd5b
add table comments per most recent migration PR
ryanulit 5ca9a94
add erd
ryanulit 3262cbc
add namespace_id to updateable query for unsafe actions
ryanulit b8822e5
add read CRUD query
ryanulit 1b103dc
address PR feedback
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
32 changes: 32 additions & 0 deletions
32
service/policy/db/migrations/20240806142109_add_resource_mapping_groups.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,32 @@ | ||
| # Diagram for 20240806142109_add_resource_mapping_groups.sql | ||
|
|
||
| ## Background | ||
|
|
||
| This schema reflects the addition of a `resource_mapping_groups` table, allowing existing Resource Mappings to be grouped by namespace and a common name. The migration also updates the `resource_mappings` table to include a `group_id` column, which will be used to optionally associate a Resource Mapping with a group. | ||
|
|
||
| # ERD | ||
|
|
||
| ```mermaid | ||
| --- | ||
| title: Database Schema Mermaid Diagram | ||
| --- | ||
|
|
||
| erDiagram | ||
|
|
||
| ResourceMappingGroup ||--|{ ResourceMapping : has | ||
|
|
||
| ResourceMappingGroup { | ||
| uuid id PK | ||
| uuid namespace_id | ||
| varchar name | ||
| compIdx comp_key UK "namespace_id + name" | ||
| } | ||
|
|
||
| ResourceMapping { | ||
| uuid id PK | ||
| uuid attribute_value_id FK | ||
| varchar[] terms | ||
| jsonb metadata | ||
| uuid group_id FK | ||
| } | ||
| ``` |
29 changes: 29 additions & 0 deletions
29
service/policy/db/migrations/20240806142109_add_resource_mapping_groups.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,29 @@ | ||
| -- +goose Up | ||
| -- +goose StatementBegin | ||
|
|
||
| CREATE TABLE IF NOT EXISTS resource_mapping_groups ( | ||
| id UUID PRIMARY KEY DEFAULT gen_random_uuid(), | ||
| namespace_id UUID NOT NULL REFERENCES attribute_namespaces(id) ON DELETE CASCADE, | ||
| name VARCHAR NOT NULL, | ||
| UNIQUE(namespace_id, name) | ||
| ); | ||
|
|
||
| COMMENT ON TABLE resource_mapping_groups IS 'Table to store the groups of resource mappings by unique namespace and group name combinations'; | ||
| COMMENT ON COLUMN resource_mapping_groups.id IS 'Primary key for the table'; | ||
| COMMENT ON COLUMN resource_mapping_groups.namespace_id IS 'Foreign key to the namespace of the attribute'; | ||
| COMMENT ON COLUMN resource_mapping_groups.name IS 'Name for the group of resource mappings'; | ||
|
|
||
| ALTER TABLE resource_mappings ADD COLUMN group_id UUID REFERENCES resource_mapping_groups(id) ON DELETE SET NULL; | ||
|
|
||
| COMMENT ON COLUMN resource_mappings.group_id IS 'Foreign key to the parent group of the resource mapping (optional, a resource mapping may not be in a group)'; | ||
|
|
||
| -- +goose StatementEnd | ||
|
|
||
| -- +goose Down | ||
| -- +goose StatementBegin | ||
|
|
||
| ALTER TABLE resource_mappings DROP COLUMN group_id; | ||
|
|
||
| DROP TABLE IF EXISTS resource_mapping_groups; | ||
|
|
||
| -- +goose StatementEnd |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.