Files
Primora/apps/backend/db/migrations/00002_collections.sql
T
2026-04-10 12:03:31 +02:00

31 lines
1.1 KiB
SQL

-- +goose Up
CREATE TABLE core.collections (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
project_id UUID NOT NULL REFERENCES core.projects(id) ON DELETE CASCADE,
slug TEXT NOT NULL,
name TEXT NOT NULL,
description TEXT,
schema JSONB NOT NULL DEFAULT '{}'::jsonb,
created_by_user_id UUID REFERENCES core.users(id) ON DELETE SET NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
UNIQUE (project_id, slug)
);
CREATE TABLE core.documents (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
collection_id UUID NOT NULL REFERENCES core.collections(id) ON DELETE CASCADE,
data JSONB NOT NULL DEFAULT '{}'::jsonb,
created_by_user_id UUID REFERENCES core.users(id) ON DELETE SET NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX idx_collections_project_id ON core.collections(project_id);
CREATE INDEX idx_documents_collection_id ON core.documents(collection_id);
CREATE INDEX idx_documents_data ON core.documents USING gin (data);
-- +goose Down
DROP TABLE IF EXISTS core.documents;
DROP TABLE IF EXISTS core.collections;