0009_code_datei.sql
Pfad: migrations/0009_code_datei.sql
Ext: sql
Größe: 930 Bytes
Geändert: 2026-07-16 10:04:32+02
-- Migration 0009: Spiegel aller Code-Dateien mit automatischer Historisierung.
-- Zweck: 1:1-Abbildung des Projektcodes in DB + Diff-Historie per Trigger.
CREATE TABLE IF NOT EXISTS code_datei (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
relativer_pfad text NOT NULL UNIQUE,
datei_name text NOT NULL,
datei_erweiterung text NOT NULL,
code text NOT NULL,
code_hash text NOT NULL,
datei_groesse bigint NOT NULL DEFAULT 0,
datei_mtime timestamptz NOT NULL DEFAULT now(),
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS idx_code_datei_relativer_pfad ON code_datei (relativer_pfad);
CREATE INDEX IF NOT EXISTS idx_code_datei_erweiterung ON code_datei (datei_erweiterung);
CREATE TRIGGER trg_touch_updated_at
BEFORE UPDATE ON code_datei
FOR EACH ROW
EXECUTE FUNCTION audit.fn_touch_updated_at();