L12 Zeiterfassung: Datenmodell, Rechte und Events für die Zeitfreigabe

Migration zeiterfassung_freigabe (TimeEntry source/approvalStatus/pendingChange,
WorkSession.manual), Rechte field:record_own_time und time:approve,
PII approvedById, Events time.approval_requested/approved/rejected.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-15 09:29:20 +02:00
co-authored by Claude Opus 5
parent d3bc7f2d29
commit 03a2ccab4f
5 changed files with 60 additions and 1 deletions
@@ -0,0 +1,24 @@
-- L12 Zeiterfassung: approval workflow for manual time entries and correction proposals.
-- Additive columns only (existing rows: tracked + approved = unchanged behaviour). No new table -> no RLS/TENANT_MODELS change.
-- CreateEnum
CREATE TYPE "TimeEntrySource" AS ENUM ('tracked', 'manual');
-- CreateEnum
CREATE TYPE "TimeApprovalStatus" AS ENUM ('approved', 'pending', 'rejected');
-- AlterTable
ALTER TABLE "time_entries" ADD COLUMN "approval_status" "TimeApprovalStatus" NOT NULL DEFAULT 'approved',
ADD COLUMN "approved_at" TIMESTAMP(3),
ADD COLUMN "approved_by_id" TEXT,
ADD COLUMN "note" TEXT,
ADD COLUMN "pending_change" JSONB,
ADD COLUMN "rejection_reason" TEXT,
ADD COLUMN "source" "TimeEntrySource" NOT NULL DEFAULT 'tracked';
-- AlterTable
ALTER TABLE "work_sessions" ADD COLUMN "manual" BOOLEAN NOT NULL DEFAULT false;
-- CreateIndex
CREATE INDEX "time_entries_tenant_id_approval_status_idx" ON "time_entries"("tenant_id", "approval_status");
+24
View File
@@ -894,6 +894,8 @@ model WorkSession {
startedOffline Boolean @default(false) @map("started_offline")
deviceInfo String? @map("device_info")
clientId String? @map("client_id")
/// L12: container session for manually recorded entries (one per user + order + day, always `ended`)
manual Boolean @default(false)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@ -917,6 +919,17 @@ enum TimeEntryType {
interruption
}
enum TimeEntrySource {
tracked
manual
}
enum TimeApprovalStatus {
approved
pending
rejected
}
model TimeEntry {
id String @id @default(cuid())
tenantId String @map("tenant_id")
@@ -930,6 +943,16 @@ model TimeEntry {
correctionReason String? @map("correction_reason")
correctedById String? @map("corrected_by_id")
clientId String? @map("client_id")
// L12 Zeiterfassung: manual entries and correction proposals need approval; only
// `approvalStatus = approved` counts for reports, totals and billing.
source TimeEntrySource @default(tracked)
approvalStatus TimeApprovalStatus @default(approved) @map("approval_status")
approvedById String? @map("approved_by_id")
approvedAt DateTime? @map("approved_at")
rejectionReason String? @map("rejection_reason")
/// proposed correction of this entry {startedAt, endedAt, type, reason, requestedAt}; old values stay valid until approval
pendingChange Json? @map("pending_change")
note String?
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@ -937,6 +960,7 @@ model TimeEntry {
@@index([tenantId, workSessionId])
@@index([tenantId, userId, startedAt])
@@index([tenantId, approvalStatus])
@@unique([tenantId, clientId])
@@map("time_entries")
}