-- Sidelinja: Notater/Scratchpad
-- Avhenger av: 0001_initial_schema.sql (nodes, workspaces)

BEGIN;

CREATE TABLE notes (
    id          UUID PRIMARY KEY REFERENCES nodes(id) ON DELETE CASCADE,
    parent_id   UUID NOT NULL REFERENCES nodes(id),
    title       TEXT NOT NULL DEFAULT '',
    content     TEXT NOT NULL DEFAULT '',
    created_by  TEXT REFERENCES users(authentik_id),
    created_at  TIMESTAMPTZ NOT NULL DEFAULT now(),
    updated_at  TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE TRIGGER trg_notes_updated_at BEFORE UPDATE ON notes
    FOR EACH ROW EXECUTE FUNCTION set_updated_at();

COMMIT;

ALTER TYPE node_type ADD VALUE IF NOT EXISTS 'note';
