Skip to content
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

feat(policy): 1256 resource mapping groups db support #1270

Merged
merged 8 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
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
}
```
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),
ryanulit marked this conversation as resolved.
Show resolved Hide resolved
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';
ryanulit marked this conversation as resolved.
Show resolved Hide resolved

-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin

ALTER TABLE resource_mappings DROP COLUMN group_id;

DROP TABLE IF EXISTS resource_mapping_groups;

-- +goose StatementEnd
12 changes: 12 additions & 0 deletions service/policy/db/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions service/policy/db/query.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
----------------------------------------------------------------
-- KEY ACCESS SERVERS
----------------------------------------------------------------

-- name: ListKeyAccessServers :many
SELECT id, uri, public_key,
Expand Down Expand Up @@ -27,3 +29,27 @@ RETURNING id;
-- name: DeleteKeyAccessServer :execrows
DELETE FROM key_access_servers WHERE id = $1;

----------------------------------------------------------------
-- RESOURCE MAPPING GROUPS
----------------------------------------------------------------

-- name: GetResourceMappingGroup :one
ryanulit marked this conversation as resolved.
Show resolved Hide resolved
SELECT id, namespace_id, name
FROM resource_mapping_groups
WHERE id = $1;

-- name: CreateResourceMappingGroup :one
INSERT INTO resource_mapping_groups (namespace_id, name)
VALUES ($1, $2)
RETURNING id;

-- name: UpdateResourceMappingGroup :one
UPDATE resource_mapping_groups
SET
namespace_id = coalesce(sqlc.narg('namespace_id'), namespace_id),
name = coalesce(sqlc.narg('name'), name)
WHERE id = $1
RETURNING id;

-- name: DeleteResourceMappingGroup :execrows
DELETE FROM resource_mapping_groups WHERE id = $1;
91 changes: 91 additions & 0 deletions service/policy/db/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading