-- CreateSchema
CREATE SCHEMA IF NOT EXISTS "platform_meeting_attendance";

-- CreateEnum
CREATE TYPE "platform_meeting_attendance"."MeetingAttendanceUserRole" AS ENUM ('ADMIN', 'MANAGER', 'LEADER', 'EMPLOYEE');

-- CreateEnum
CREATE TYPE "platform_meeting_attendance"."RecurrencePattern" AS ENUM ('DAILY', 'WEEKLY', 'MONTHLY', 'YEARLY');

-- CreateEnum
CREATE TYPE "platform_meeting_attendance"."MeetingType" AS ENUM ('OFFLINE', 'ONLINE', 'HYBRID');

-- CreateEnum
CREATE TYPE "platform_meeting_attendance"."MeetingStatus" AS ENUM ('SCHEDULED', 'IN_PROGRESS', 'COMPLETED', 'CANCELLED');

-- CreateEnum
CREATE TYPE "platform_meeting_attendance"."AttendeeRole" AS ENUM ('C_SUITE_ATTENDEE', 'LEVEL_1_REPORT_ATTENDEE', 'LEVEL_2_REPORT_ATTENDEE', 'MEETING_OPERATIONS', 'REGULAR_ATTENDEE', 'OPTIONAL_ATTENDEE');

-- CreateEnum
CREATE TYPE "platform_meeting_attendance"."AttendanceStatus" AS ENUM ('NOT_CHECKED_IN', 'ON_SITE', 'ONLINE', 'ABSENT', 'PTO', 'BUSINESS_CONFLICT', 'LATE', 'MEETING');

-- CreateEnum
CREATE TYPE "platform_meeting_attendance"."CheckinType" AS ENUM ('QR_CODE', 'NFC', 'MANUAL', 'ONLINE');

-- CreateEnum
CREATE TYPE "platform_meeting_attendance"."LeaveType" AS ENUM ('SICK', 'PERSONAL', 'ANNUAL', 'BUSINESS', 'OTHER');

-- CreateEnum
CREATE TYPE "platform_meeting_attendance"."LeaveStatus" AS ENUM ('PENDING', 'APPROVED', 'REJECTED');

-- CreateTable
CREATE TABLE "platform_meeting_attendance"."users" (
    "id" VARCHAR(32) NOT NULL,
    "platform_user_id" UUID,
    "email" VARCHAR(255) NOT NULL,
    "name" VARCHAR(200) NOT NULL,
    "password" VARCHAR(255),
    "require_password_change" BOOLEAN NOT NULL DEFAULT false,
    "avatar" VARCHAR(500),
    "role" "platform_meeting_attendance"."MeetingAttendanceUserRole" NOT NULL DEFAULT 'EMPLOYEE',
    "company" VARCHAR(200),
    "department" VARCHAR(200),
    "position" VARCHAR(200),
    "is_active" BOOLEAN NOT NULL DEFAULT true,
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,

    CONSTRAINT "users_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "platform_meeting_attendance"."meetings" (
    "id" VARCHAR(32) NOT NULL,
    "title" VARCHAR(200) NOT NULL,
    "description" TEXT,
    "start_time" TIMESTAMPTZ(3) NOT NULL,
    "end_time" TIMESTAMPTZ(3) NOT NULL,
    "timezone" VARCHAR(50) NOT NULL DEFAULT 'UTC',
    "location" VARCHAR(200),
    "type" "platform_meeting_attendance"."MeetingType" NOT NULL DEFAULT 'OFFLINE',
    "status" "platform_meeting_attendance"."MeetingStatus" NOT NULL DEFAULT 'SCHEDULED',
    "qr_code_online" TEXT,
    "qr_code_offline" TEXT,
    "creator_id" VARCHAR(32) NOT NULL,
    "series_id" VARCHAR(32),
    "instance_number" INTEGER,
    "is_series_master" BOOLEAN NOT NULL DEFAULT false,
    "has_custom_attendees" BOOLEAN NOT NULL DEFAULT false,
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,

    CONSTRAINT "meetings_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "platform_meeting_attendance"."meeting_series" (
    "id" VARCHAR(32) NOT NULL,
    "title" VARCHAR(200) NOT NULL,
    "description" TEXT,
    "pattern" "platform_meeting_attendance"."RecurrencePattern" NOT NULL,
    "frequency" INTEGER NOT NULL DEFAULT 1,
    "start_date" TIMESTAMPTZ(3) NOT NULL,
    "end_date" TIMESTAMPTZ(3),
    "max_occurrences" INTEGER,
    "timezone" VARCHAR(50) NOT NULL DEFAULT 'UTC',
    "location" VARCHAR(200),
    "type" "platform_meeting_attendance"."MeetingType" NOT NULL DEFAULT 'OFFLINE',
    "creator_id" VARCHAR(32) NOT NULL,
    "is_active" BOOLEAN NOT NULL DEFAULT true,
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,

    CONSTRAINT "meeting_series_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "platform_meeting_attendance"."attendances" (
    "id" VARCHAR(32) NOT NULL,
    "user_id" VARCHAR(32) NOT NULL,
    "meeting_id" VARCHAR(32) NOT NULL,
    "status" "platform_meeting_attendance"."AttendanceStatus" NOT NULL DEFAULT 'ABSENT',
    "checkin_time" TIMESTAMPTZ(3),
    "checkout_time" TIMESTAMPTZ(3),
    "is_late" BOOLEAN NOT NULL DEFAULT false,
    "is_early_leave" BOOLEAN NOT NULL DEFAULT false,
    "notes" TEXT,
    "checkin_type" "platform_meeting_attendance"."CheckinType",
    "device_id" VARCHAR(100),
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,

    CONSTRAINT "attendances_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "platform_meeting_attendance"."meeting_required_attendees" (
    "id" VARCHAR(32) NOT NULL,
    "meeting_id" VARCHAR(32) NOT NULL,
    "user_id" VARCHAR(32),
    "role" "platform_meeting_attendance"."AttendeeRole" NOT NULL DEFAULT 'OPTIONAL_ATTENDEE',
    "company" VARCHAR(200),
    "department" VARCHAR(200),
    "email" VARCHAR(255),
    "name" VARCHAR(200),
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "meeting_required_attendees_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "platform_meeting_attendance"."meeting_templates" (
    "id" VARCHAR(32) NOT NULL,
    "name" VARCHAR(200) NOT NULL,
    "title" VARCHAR(200) NOT NULL,
    "description" TEXT,
    "duration" INTEGER NOT NULL,
    "timezone" VARCHAR(50) NOT NULL DEFAULT 'UTC',
    "location" VARCHAR(200),
    "type" "platform_meeting_attendance"."MeetingType" NOT NULL DEFAULT 'OFFLINE',
    "creator_id" VARCHAR(32) NOT NULL,
    "is_public" BOOLEAN NOT NULL DEFAULT false,
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,

    CONSTRAINT "meeting_templates_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "platform_meeting_attendance"."meeting_template_attendees" (
    "id" VARCHAR(32) NOT NULL,
    "template_id" VARCHAR(32) NOT NULL,
    "user_id" VARCHAR(32) NOT NULL,
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "meeting_template_attendees_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "platform_meeting_attendance"."leave_records" (
    "id" VARCHAR(32) NOT NULL,
    "user_id" VARCHAR(32) NOT NULL,
    "type" "platform_meeting_attendance"."LeaveType" NOT NULL,
    "start_date" TIMESTAMPTZ(3) NOT NULL,
    "end_date" TIMESTAMPTZ(3) NOT NULL,
    "reason" TEXT,
    "status" "platform_meeting_attendance"."LeaveStatus" NOT NULL DEFAULT 'PENDING',
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,

    CONSTRAINT "leave_records_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "platform_meeting_attendance"."accounts" (
    "id" VARCHAR(32) NOT NULL,
    "user_id" VARCHAR(32) NOT NULL,
    "type" VARCHAR(50) NOT NULL,
    "provider" VARCHAR(50) NOT NULL,
    "provider_account_id" VARCHAR(200) NOT NULL,
    "refresh_token" TEXT,
    "access_token" TEXT,
    "expires_at" INTEGER,
    "token_type" VARCHAR(50),
    "scope" TEXT,
    "id_token" TEXT,
    "session_state" TEXT,

    CONSTRAINT "accounts_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "platform_meeting_attendance"."sessions" (
    "id" VARCHAR(32) NOT NULL,
    "session_token" VARCHAR(200) NOT NULL,
    "user_id" VARCHAR(32) NOT NULL,
    "expires" TIMESTAMPTZ(3) NOT NULL,

    CONSTRAINT "sessions_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "platform_meeting_attendance"."verification_tokens" (
    "identifier" VARCHAR(200) NOT NULL,
    "token" VARCHAR(200) NOT NULL,
    "expires" TIMESTAMPTZ(3) NOT NULL
);

-- CreateTable
CREATE TABLE "platform_meeting_attendance"."audit_logs" (
    "id" VARCHAR(32) NOT NULL,
    "user_id" VARCHAR(32),
    "user_email" VARCHAR(255) NOT NULL,
    "user_name" VARCHAR(200) NOT NULL,
    "user_role" VARCHAR(50) NOT NULL,
    "action" VARCHAR(100) NOT NULL,
    "resource" VARCHAR(100) NOT NULL,
    "resource_id" VARCHAR(64),
    "method" VARCHAR(10) NOT NULL,
    "endpoint" VARCHAR(255) NOT NULL,
    "status_code" INTEGER NOT NULL,
    "source" VARCHAR(50) NOT NULL DEFAULT 'WEB',
    "device_id" VARCHAR(100),
    "session_id" VARCHAR(100),
    "request_id" VARCHAR(100),
    "trace_id" VARCHAR(100),
    "geo_location" VARCHAR(255),
    "ip_address" VARCHAR(100),
    "user_agent" TEXT,
    "field_diffs" TEXT,
    "request_body" TEXT,
    "changes" TEXT,
    "reason_code" VARCHAR(50),
    "reason_text" TEXT,
    "error_message" TEXT,
    "prev_hash" VARCHAR(100),
    "hash" VARCHAR(100),
    "is_redacted" BOOLEAN NOT NULL DEFAULT false,
    "is_tombstoned" BOOLEAN NOT NULL DEFAULT false,
    "retention_until" TIMESTAMPTZ(3),
    "duration_ms" INTEGER,
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "audit_logs_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "platform_meeting_attendance"."data_access_logs" (
    "id" VARCHAR(32) NOT NULL,
    "actor_id" VARCHAR(32),
    "actor_email" VARCHAR(255) NOT NULL,
    "actor_name" VARCHAR(200) NOT NULL,
    "actor_role" VARCHAR(50) NOT NULL,
    "access_type" VARCHAR(100) NOT NULL,
    "entity_type" VARCHAR(100) NOT NULL,
    "entity_ids" TEXT,
    "result_count" INTEGER NOT NULL,
    "has_sensitive_data" BOOLEAN NOT NULL DEFAULT false,
    "sensitive_fields" TEXT,
    "endpoint" VARCHAR(255) NOT NULL,
    "method" VARCHAR(10) NOT NULL,
    "status_code" INTEGER NOT NULL,
    "ip_address" VARCHAR(100),
    "session_id" VARCHAR(100),
    "request_id" VARCHAR(100),
    "device_id" VARCHAR(100),
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "data_access_logs_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "platform_meeting_attendance"."audit_alert_rules" (
    "id" VARCHAR(32) NOT NULL,
    "name" VARCHAR(200) NOT NULL,
    "description" TEXT,
    "rule_type" VARCHAR(100) NOT NULL,
    "conditions" TEXT NOT NULL,
    "threshold" INTEGER,
    "time_window" INTEGER,
    "severity" VARCHAR(50) NOT NULL,
    "is_enabled" BOOLEAN NOT NULL DEFAULT true,
    "notify_email" BOOLEAN NOT NULL DEFAULT true,
    "notify_in_app" BOOLEAN NOT NULL DEFAULT true,
    "notify_webhook" BOOLEAN NOT NULL DEFAULT false,
    "webhook_url" VARCHAR(500),
    "suppression_window" INTEGER,
    "last_triggered" TIMESTAMPTZ(3),
    "trigger_count" INTEGER NOT NULL DEFAULT 0,
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,

    CONSTRAINT "audit_alert_rules_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "platform_meeting_attendance"."audit_alerts" (
    "id" VARCHAR(32) NOT NULL,
    "rule_id" VARCHAR(32) NOT NULL,
    "severity" VARCHAR(50) NOT NULL,
    "title" VARCHAR(200) NOT NULL,
    "description" TEXT NOT NULL,
    "trigger_data" TEXT NOT NULL,
    "matched_logs" TEXT NOT NULL,
    "affected_entities" TEXT,
    "status" VARCHAR(50) NOT NULL DEFAULT 'OPEN',
    "acknowledged_by" VARCHAR(32),
    "acknowledged_at" TIMESTAMPTZ(3),
    "resolved_by" VARCHAR(32),
    "resolved_at" TIMESTAMPTZ(3),
    "resolution" TEXT,
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,

    CONSTRAINT "audit_alerts_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "platform_meeting_attendance"."retention_policies" (
    "id" VARCHAR(32) NOT NULL,
    "entity_type" VARCHAR(100) NOT NULL,
    "hot_days" INTEGER NOT NULL DEFAULT 365,
    "warm_days" INTEGER NOT NULL DEFAULT 730,
    "cold_days" INTEGER NOT NULL DEFAULT 2555,
    "auto_archive" BOOLEAN NOT NULL DEFAULT true,
    "auto_delete" BOOLEAN NOT NULL DEFAULT false,
    "is_active" BOOLEAN NOT NULL DEFAULT true,
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,

    CONSTRAINT "retention_policies_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "users_email_key" ON "platform_meeting_attendance"."users"("email");

-- CreateIndex
CREATE UNIQUE INDEX "attendances_user_id_meeting_id_key" ON "platform_meeting_attendance"."attendances"("user_id", "meeting_id");

-- CreateIndex
CREATE UNIQUE INDEX "meeting_required_attendees_meeting_id_user_id_key" ON "platform_meeting_attendance"."meeting_required_attendees"("meeting_id", "user_id");

-- CreateIndex
CREATE UNIQUE INDEX "meeting_template_attendees_template_id_user_id_key" ON "platform_meeting_attendance"."meeting_template_attendees"("template_id", "user_id");

-- CreateIndex
CREATE UNIQUE INDEX "accounts_provider_provider_account_id_key" ON "platform_meeting_attendance"."accounts"("provider", "provider_account_id");

-- CreateIndex
CREATE UNIQUE INDEX "sessions_session_token_key" ON "platform_meeting_attendance"."sessions"("session_token");

-- CreateIndex
CREATE UNIQUE INDEX "verification_tokens_token_key" ON "platform_meeting_attendance"."verification_tokens"("token");

-- CreateIndex
CREATE UNIQUE INDEX "verification_tokens_identifier_token_key" ON "platform_meeting_attendance"."verification_tokens"("identifier", "token");

-- CreateIndex
CREATE INDEX "audit_logs_user_id_idx" ON "platform_meeting_attendance"."audit_logs"("user_id");

-- CreateIndex
CREATE INDEX "audit_logs_user_email_idx" ON "platform_meeting_attendance"."audit_logs"("user_email");

-- CreateIndex
CREATE INDEX "audit_logs_action_idx" ON "platform_meeting_attendance"."audit_logs"("action");

-- CreateIndex
CREATE INDEX "audit_logs_resource_idx" ON "platform_meeting_attendance"."audit_logs"("resource");

-- CreateIndex
CREATE INDEX "audit_logs_resource_id_idx" ON "platform_meeting_attendance"."audit_logs"("resource_id");

-- CreateIndex
CREATE INDEX "audit_logs_created_at_idx" ON "platform_meeting_attendance"."audit_logs"("created_at");

-- CreateIndex
CREATE INDEX "audit_logs_trace_id_idx" ON "platform_meeting_attendance"."audit_logs"("trace_id");

-- CreateIndex
CREATE INDEX "audit_logs_session_id_idx" ON "platform_meeting_attendance"."audit_logs"("session_id");

-- CreateIndex
CREATE INDEX "audit_logs_device_id_idx" ON "platform_meeting_attendance"."audit_logs"("device_id");

-- CreateIndex
CREATE INDEX "audit_logs_source_idx" ON "platform_meeting_attendance"."audit_logs"("source");

-- CreateIndex
CREATE INDEX "audit_logs_status_code_idx" ON "platform_meeting_attendance"."audit_logs"("status_code");

-- CreateIndex
CREATE INDEX "data_access_logs_actor_id_idx" ON "platform_meeting_attendance"."data_access_logs"("actor_id");

-- CreateIndex
CREATE INDEX "data_access_logs_actor_email_idx" ON "platform_meeting_attendance"."data_access_logs"("actor_email");

-- CreateIndex
CREATE INDEX "data_access_logs_access_type_idx" ON "platform_meeting_attendance"."data_access_logs"("access_type");

-- CreateIndex
CREATE INDEX "data_access_logs_entity_type_idx" ON "platform_meeting_attendance"."data_access_logs"("entity_type");

-- CreateIndex
CREATE INDEX "data_access_logs_created_at_idx" ON "platform_meeting_attendance"."data_access_logs"("created_at");

-- CreateIndex
CREATE UNIQUE INDEX "audit_alert_rules_name_key" ON "platform_meeting_attendance"."audit_alert_rules"("name");

-- CreateIndex
CREATE INDEX "audit_alert_rules_rule_type_idx" ON "platform_meeting_attendance"."audit_alert_rules"("rule_type");

-- CreateIndex
CREATE INDEX "audit_alert_rules_severity_idx" ON "platform_meeting_attendance"."audit_alert_rules"("severity");

-- CreateIndex
CREATE INDEX "audit_alert_rules_is_enabled_idx" ON "platform_meeting_attendance"."audit_alert_rules"("is_enabled");

-- CreateIndex
CREATE INDEX "audit_alerts_rule_id_idx" ON "platform_meeting_attendance"."audit_alerts"("rule_id");

-- CreateIndex
CREATE INDEX "audit_alerts_status_idx" ON "platform_meeting_attendance"."audit_alerts"("status");

-- CreateIndex
CREATE INDEX "audit_alerts_severity_idx" ON "platform_meeting_attendance"."audit_alerts"("severity");

-- CreateIndex
CREATE INDEX "audit_alerts_created_at_idx" ON "platform_meeting_attendance"."audit_alerts"("created_at");

-- CreateIndex
CREATE UNIQUE INDEX "retention_policies_entity_type_key" ON "platform_meeting_attendance"."retention_policies"("entity_type");

-- AddForeignKey
ALTER TABLE "platform_meeting_attendance"."meetings" ADD CONSTRAINT "meetings_series_id_fkey" FOREIGN KEY ("series_id") REFERENCES "platform_meeting_attendance"."meeting_series"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_meeting_attendance"."meetings" ADD CONSTRAINT "meetings_creator_id_fkey" FOREIGN KEY ("creator_id") REFERENCES "platform_meeting_attendance"."users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_meeting_attendance"."meeting_series" ADD CONSTRAINT "meeting_series_creator_id_fkey" FOREIGN KEY ("creator_id") REFERENCES "platform_meeting_attendance"."users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_meeting_attendance"."attendances" ADD CONSTRAINT "attendances_meeting_id_fkey" FOREIGN KEY ("meeting_id") REFERENCES "platform_meeting_attendance"."meetings"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_meeting_attendance"."attendances" ADD CONSTRAINT "attendances_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "platform_meeting_attendance"."users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_meeting_attendance"."meeting_required_attendees" ADD CONSTRAINT "meeting_required_attendees_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "platform_meeting_attendance"."users"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_meeting_attendance"."meeting_required_attendees" ADD CONSTRAINT "meeting_required_attendees_meeting_id_fkey" FOREIGN KEY ("meeting_id") REFERENCES "platform_meeting_attendance"."meetings"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_meeting_attendance"."meeting_templates" ADD CONSTRAINT "meeting_templates_creator_id_fkey" FOREIGN KEY ("creator_id") REFERENCES "platform_meeting_attendance"."users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_meeting_attendance"."meeting_template_attendees" ADD CONSTRAINT "meeting_template_attendees_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "platform_meeting_attendance"."users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_meeting_attendance"."meeting_template_attendees" ADD CONSTRAINT "meeting_template_attendees_template_id_fkey" FOREIGN KEY ("template_id") REFERENCES "platform_meeting_attendance"."meeting_templates"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_meeting_attendance"."leave_records" ADD CONSTRAINT "leave_records_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "platform_meeting_attendance"."users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_meeting_attendance"."accounts" ADD CONSTRAINT "accounts_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "platform_meeting_attendance"."users"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_meeting_attendance"."sessions" ADD CONSTRAINT "sessions_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "platform_meeting_attendance"."users"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_meeting_attendance"."audit_logs" ADD CONSTRAINT "audit_logs_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "platform_meeting_attendance"."users"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_meeting_attendance"."audit_alerts" ADD CONSTRAINT "audit_alerts_rule_id_fkey" FOREIGN KEY ("rule_id") REFERENCES "platform_meeting_attendance"."audit_alert_rules"("id") ON DELETE CASCADE ON UPDATE CASCADE;
