From f1879dc15cf6847b088cd21f5c025a4e7c9ed8f3 Mon Sep 17 00:00:00 2001 From: dal Date: Tue, 28 Jan 2025 09:57:40 -0700 Subject: [PATCH] new tables --- .../down.sql | 10 ++++++++ .../2025-01-27-235858_dashboard_files/up.sql | 23 +++++++++++++++++++ .../down.sql | 1 + .../up.sql | 1 + 4 files changed, 35 insertions(+) create mode 100644 api/migrations/2025-01-28-164827_file_junction_table/down.sql create mode 100644 api/migrations/2025-01-28-164827_file_junction_table/up.sql diff --git a/api/migrations/2025-01-27-235858_dashboard_files/down.sql b/api/migrations/2025-01-27-235858_dashboard_files/down.sql index d9a93fe9a..3af8a2af4 100644 --- a/api/migrations/2025-01-27-235858_dashboard_files/down.sql +++ b/api/migrations/2025-01-27-235858_dashboard_files/down.sql @@ -1 +1,11 @@ -- This file should undo anything in `up.sql` +-- Drop trigger first +DROP TRIGGER IF EXISTS set_timestamp ON dashboard_files; + +-- Drop indexes +DROP INDEX IF EXISTS dashboard_files_deleted_at_idx; +DROP INDEX IF EXISTS dashboard_files_created_by_idx; +DROP INDEX IF EXISTS dashboard_files_organization_id_idx; + +-- Drop table +DROP TABLE IF EXISTS dashboard_files; diff --git a/api/migrations/2025-01-27-235858_dashboard_files/up.sql b/api/migrations/2025-01-27-235858_dashboard_files/up.sql index b37f10d95..1612abd75 100644 --- a/api/migrations/2025-01-27-235858_dashboard_files/up.sql +++ b/api/migrations/2025-01-27-235858_dashboard_files/up.sql @@ -1 +1,24 @@ -- Your SQL goes here +CREATE TABLE dashboard_files ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + name VARCHAR NOT NULL, + file_name VARCHAR NOT NULL, + content JSONB NOT NULL, + filter VARCHAR, + organization_id UUID NOT NULL, + created_by UUID NOT NULL, + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + deleted_at TIMESTAMP WITH TIME ZONE +); + +-- Add indexes +CREATE INDEX dashboard_files_organization_id_idx ON dashboard_files(organization_id); +CREATE INDEX dashboard_files_created_by_idx ON dashboard_files(created_by); +CREATE INDEX dashboard_files_deleted_at_idx ON dashboard_files(deleted_at); + +-- Add trigger to update updated_at timestamp +CREATE TRIGGER set_timestamp + BEFORE UPDATE ON dashboard_files + FOR EACH ROW + EXECUTE PROCEDURE trigger_set_timestamp(); diff --git a/api/migrations/2025-01-28-164827_file_junction_table/down.sql b/api/migrations/2025-01-28-164827_file_junction_table/down.sql new file mode 100644 index 000000000..d9a93fe9a --- /dev/null +++ b/api/migrations/2025-01-28-164827_file_junction_table/down.sql @@ -0,0 +1 @@ +-- This file should undo anything in `up.sql` diff --git a/api/migrations/2025-01-28-164827_file_junction_table/up.sql b/api/migrations/2025-01-28-164827_file_junction_table/up.sql new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/api/migrations/2025-01-28-164827_file_junction_table/up.sql @@ -0,0 +1 @@ +