Files
evig/scripts/db/migrations/091_time_off_requests.sql
Mao NakamotoandClaude Opus 4.8 43cc49c489 feat(db): time_off_requests table (091) — applied to Neon
Schema for the upcoming self-service time-off request + approval cycle.
Recorded in schema_migrations; the table already exists on Neon so repo and
live DB stay in sync. Feature code (API/UI) lands in a follow-up.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-18 15:17:14 +02:00

32 lines
1.7 KiB
SQL

-- ============================================================================
-- 091_time_off_requests.sql
--
-- Self-service time-off requests with an approval cycle. A staff member
-- requests future leave (vacation, unpaid, military, …); an approver
-- (super admin or staff with the `timecards` permission) approves or
-- rejects it. Distinct from `timecard_entries` (which log actual worked /
-- absent days) and from `leave_periods` (HR's authoritative leave record) —
-- an approved request can be materialised into a leave_period.
-- ============================================================================
CREATE TABLE IF NOT EXISTS time_off_requests (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
kind TEXT NOT NULL CHECK (kind IN ('ferien', 'unbezahlt', 'militaer', 'unfall', 'other')),
starts_on DATE NOT NULL,
ends_on DATE NOT NULL,
half_day BOOLEAN NOT NULL DEFAULT false,
note TEXT,
status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'approved', 'rejected', 'cancelled')),
reviewed_by UUID REFERENCES users(id) ON DELETE SET NULL,
reviewed_at TIMESTAMPTZ,
review_notes TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
CONSTRAINT time_off_requests_range_ck CHECK (ends_on >= starts_on)
);
CREATE INDEX IF NOT EXISTS idx_time_off_requests_user ON time_off_requests(user_id);
CREATE INDEX IF NOT EXISTS idx_time_off_requests_status ON time_off_requests(status);
CREATE INDEX IF NOT EXISTS idx_time_off_requests_period ON time_off_requests(starts_on, ends_on);