smart_ide/services/docv/docv-back/migrations/20260330140000_offices_folders.sql
Nicolas Cantu 01860b7af7 chore: remove gitmodules, add docv workspace crates, update systemd README
- Drop .gitmodules (ia_dev tracked as submodule pointer without file)
- Add services/docv Cargo workspace: docv-back, docv-shared, migrations, sources
- Refresh systemd/README.md
2026-04-03 17:55:50 +02:00

31 lines
1.1 KiB
SQL

-- Minimal offices / memberships / folders for docv API (zones 5 & 2 subset).
-- user_uid matches users primary key value (UUID as text from JWT sub) without DB FK (supports id or uid PK on users).
CREATE TABLE IF NOT EXISTS offices (
uid UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name TEXT NOT NULL,
siren TEXT,
address TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE TABLE IF NOT EXISTS office_members (
office_uid UUID NOT NULL REFERENCES offices(uid) ON DELETE CASCADE,
user_uid UUID NOT NULL,
role TEXT NOT NULL DEFAULT 'member',
PRIMARY KEY (office_uid, user_uid)
);
CREATE INDEX IF NOT EXISTS idx_office_members_user ON office_members(user_uid);
CREATE TABLE IF NOT EXISTS folders (
uid UUID PRIMARY KEY DEFAULT gen_random_uuid(),
office_uid UUID NOT NULL REFERENCES offices(uid) ON DELETE CASCADE,
title TEXT NOT NULL,
status TEXT NOT NULL DEFAULT 'open',
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS idx_folders_office ON folders(office_uid);