From 6a38f3b4ea70f8844b96066979cdfe7e19751640 Mon Sep 17 00:00:00 2001 From: William Valentin Date: Sun, 1 Feb 2026 17:41:34 -0800 Subject: [PATCH] feat: add tags, albums, and audit log tables --- .../db/migrations/0004_tags_albums_audit.sql | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 packages/db/migrations/0004_tags_albums_audit.sql diff --git a/packages/db/migrations/0004_tags_albums_audit.sql b/packages/db/migrations/0004_tags_albums_audit.sql new file mode 100644 index 0000000..7b8bf26 --- /dev/null +++ b/packages/db/migrations/0004_tags_albums_audit.sql @@ -0,0 +1,34 @@ +CREATE TABLE IF NOT EXISTS tags ( + id uuid PRIMARY KEY DEFAULT gen_random_uuid(), + name text NOT NULL UNIQUE, + created_at timestamptz NOT NULL DEFAULT now() +); + +CREATE TABLE IF NOT EXISTS asset_tags ( + asset_id uuid NOT NULL REFERENCES assets(id) ON DELETE CASCADE, + tag_id uuid NOT NULL REFERENCES tags(id) ON DELETE CASCADE, + PRIMARY KEY(asset_id, tag_id) +); + +CREATE TABLE IF NOT EXISTS albums ( + id uuid PRIMARY KEY DEFAULT gen_random_uuid(), + name text NOT NULL, + created_at timestamptz NOT NULL DEFAULT now() +); + +CREATE TABLE IF NOT EXISTS album_assets ( + album_id uuid NOT NULL REFERENCES albums(id) ON DELETE CASCADE, + asset_id uuid NOT NULL REFERENCES assets(id) ON DELETE CASCADE, + ord int, + PRIMARY KEY(album_id, asset_id) +); + +CREATE TABLE IF NOT EXISTS audit_log ( + id uuid PRIMARY KEY DEFAULT gen_random_uuid(), + actor text NOT NULL, + action text NOT NULL, + entity_type text NOT NULL, + entity_id uuid, + payload jsonb, + created_at timestamptz NOT NULL DEFAULT now() +);