-- CreateEnum
CREATE TYPE "gender" AS ENUM ('Male', 'Female', 'Transgender');

-- CreateEnum
CREATE TYPE "hostel_status_type" AS ENUM ('Maintanance', 'Repair', 'Broken');

-- CreateEnum
CREATE TYPE "template_type" AS ENUM ('SMS', 'email');

-- CreateEnum
CREATE TYPE "question_type" AS ENUM ('text', 'number', 'select');

-- CreateEnum
CREATE TYPE "sponsor_type" AS ENUM ('GOI', 'GOTN', 'OBP');

-- CreateEnum
CREATE TYPE "food_type" AS ENUM ('Veg', 'NonVeg');

-- CreateTable
CREATE TABLE "api_module" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "role" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "api_access" JSONB,
    "home_page" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "ui_module" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "ui_module_component" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "is_item_specific" BOOLEAN NOT NULL DEFAULT false,
    "ui_module_id" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "ui_module_component_api_module" (
    "id" TEXT NOT NULL,
    "ui_module_component_id" TEXT NOT NULL,
    "api_module_id" TEXT NOT NULL,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "ui_module_component_role_access" (
    "id" TEXT NOT NULL,
    "ui_module_component_id" TEXT NOT NULL,
    "role_id" TEXT NOT NULL,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "ui_module_role_access" (
    "id" TEXT NOT NULL,
    "ui_module_id" TEXT NOT NULL,
    "role_id" TEXT NOT NULL,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "audit_log" (
    "id" TEXT NOT NULL,
    "table_name" TEXT NOT NULL,
    "action" TEXT NOT NULL,
    "item_id" TEXT NOT NULL,
    "version" INTEGER NOT NULL,
    "address" TEXT,
    "user_id" TEXT,
    "fields" JSONB[],
    "date_time" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "user" (
    "id" TEXT NOT NULL,
    "name" TEXT,
    "password" TEXT,
    "salt" TEXT,
    "email" TEXT,
    "force_password_change" BOOLEAN,
    "icon" TEXT,
    "is_active" BOOLEAN DEFAULT true,
    "is_deleted" BOOLEAN DEFAULT false,
    "last_login_datetime" TIMETZ(6),
    "mobile" TEXT,
    "password_valid_from" INTEGER,
    "username" TEXT NOT NULL,
    "is_debug" BOOLEAN DEFAULT false,
    "districtId" TEXT,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "user_role" (
    "id" TEXT NOT NULL,
    "user_id" TEXT NOT NULL,
    "role_id" TEXT NOT NULL,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "state" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "district" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "zipcodes" TEXT[],
    "state_id" TEXT,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "department" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "email" TEXT,
    "contact_person_name" TEXT,
    "contact_person_mobile" TEXT,
    "contact_person_email" TEXT,
    "address" TEXT NOT NULL,
    "parent_department_id" TEXT,
    "is_district_department" BOOLEAN NOT NULL DEFAULT false,
    "district_id" TEXT,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,
    "hod_name" TEXT NOT NULL,
    "hod_mobile" TEXT,
    "hod_email" TEXT,
    "hod_designation" TEXT,
    "contact_person_designation" TEXT,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "faculty" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "photo_url" TEXT NOT NULL DEFAULT E'',
    "mobile" TEXT NOT NULL,
    "address" TEXT,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,
    "user_id" TEXT NOT NULL,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "course_director" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "photo_url" TEXT NOT NULL DEFAULT E'',
    "mobile" TEXT,
    "address" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,
    "user_id" TEXT NOT NULL,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "data_entry_operator" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "photo_url" TEXT NOT NULL DEFAULT E'',
    "mobile" TEXT NOT NULL,
    "address" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,
    "user_id" TEXT NOT NULL,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "programme_master" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "code" TEXT NOT NULL,
    "objective" TEXT NOT NULL,
    "no_of_days" INTEGER NOT NULL,
    "course_director_id" TEXT NOT NULL,
    "sponsor" "sponsor_type" NOT NULL,
    "department_id" TEXT,
    "max_candidates" INTEGER NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "programme_session_master" (
    "id" TEXT NOT NULL,
    "programme_master_id" TEXT NOT NULL,
    "session_title" TEXT NOT NULL,
    "no_of_classes" INTEGER NOT NULL,
    "order" INTEGER NOT NULL,
    "session_objective" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "programme" (
    "id" TEXT NOT NULL,
    "programme_master_id" TEXT NOT NULL,
    "programme_department_id" TEXT,
    "from_date" TIMESTAMP(3) NOT NULL,
    "to_date" TIMESTAMP(3) NOT NULL,
    "show_from_date" TIMESTAMP(3) NOT NULL,
    "name" TEXT NOT NULL,
    "code" TEXT NOT NULL,
    "objective" TEXT NOT NULL,
    "is_hostel_allowed" BOOLEAN NOT NULL,
    "call_letter_id" TEXT,
    "is_rescheduled" BOOLEAN NOT NULL DEFAULT false,
    "is_rtc" BOOLEAN NOT NULL DEFAULT false,
    "max_candidates" INTEGER NOT NULL,
    "last_updated_date_time" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "group_photo_url" TEXT,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,
    "rtc_district_id" TEXT,
    "regional_training_center_id" TEXT,
    "rtc_locationId" TEXT,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "regional_training_center" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "address" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "rtc_district" (
    "id" TEXT NOT NULL,
    "regional_training_center_id" TEXT NOT NULL,
    "district_id" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,
    "rtc_locationId" TEXT,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "rtc_location" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "lat" DOUBLE PRECISION NOT NULL,
    "long" DOUBLE PRECISION NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "programme_department" (
    "id" TEXT NOT NULL,
    "department_id" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "email_log" (
    "id" TEXT NOT NULL,
    "email" TEXT NOT NULL,
    "subject" TEXT NOT NULL,
    "content" TEXT NOT NULL,
    "status" TEXT NOT NULL,
    "message_id" TEXT NOT NULL,
    "message_size" TEXT NOT NULL,
    "message_time" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "programme_session" (
    "id" TEXT NOT NULL,
    "programme_session_master_id" TEXT,
    "programme_id" TEXT NOT NULL,
    "faculty_id" TEXT,
    "qr_code" TEXT,
    "session_hour" INTEGER,
    "session_date" TIMESTAMP(3) NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,
    "created_date_time" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "programme_call_letter" (
    "id" TEXT NOT NULL,
    "template_id" TEXT NOT NULL,
    "content" TEXT NOT NULL,
    "email_subject" TEXT NOT NULL,
    "programme_id" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "programme_rescheduledate" (
    "id" TEXT NOT NULL,
    "programme_id" TEXT NOT NULL,
    "from_date" TIMESTAMP(3) NOT NULL,
    "to_date" TIMESTAMP(3) NOT NULL,
    "rescheduled_from_date" TIMESTAMP(3) NOT NULL,
    "rescheduled_to_date" TIMESTAMP(3) NOT NULL,
    "rescheduled_on" TIMESTAMP(3) NOT NULL,
    "rescheduled_by_id" TEXT NOT NULL,
    "client_ip" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "template" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "email_subject" TEXT NOT NULL,
    "content" TEXT,
    "type" "template_type" NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "hostel_building" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,
    "building_number" INTEGER NOT NULL,
    "status" "hostel_status_type" NOT NULL,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "hostel_block" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,
    "block_number" INTEGER NOT NULL,
    "status" "hostel_status_type" NOT NULL,
    "hostel_building_id" TEXT NOT NULL,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "hostel_floor" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "floor_number" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,
    "status" "hostel_status_type" NOT NULL,
    "hostel_block_id" TEXT NOT NULL,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "hostel_room" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "room_number" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,
    "status" "hostel_status_type" NOT NULL,
    "hostel_floor_id" TEXT NOT NULL,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "hostel_bed" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "bed_number" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,
    "status" "hostel_status_type" NOT NULL,
    "hostel_room_id" TEXT NOT NULL,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "hostel_room_checkin" (
    "id" TEXT NOT NULL,
    "checkin_date_time" TIMESTAMP(3) NOT NULL,
    "checkout_date_time" TIMESTAMP(3) NOT NULL,
    "remarks" TEXT NOT NULL,
    "programme_candidate_id" TEXT NOT NULL,
    "hostel_bed_id" TEXT NOT NULL,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "officer" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "mobile" TEXT,
    "designation" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,
    "user_id" TEXT NOT NULL,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "candidate" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "mobile" TEXT,
    "email" TEXT,
    "address" TEXT NOT NULL,
    "gender" "gender" NOT NULL,
    "designation" TEXT NOT NULL,
    "department_id" TEXT NOT NULL,
    "client_ip" TEXT NOT NULL,
    "is_handicapped" BOOLEAN NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,
    "registered_date_time" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "programme_candidate" (
    "id" TEXT NOT NULL,
    "programme_id" TEXT NOT NULL,
    "hostel_needed" BOOLEAN NOT NULL,
    "food_preference" "food_type" NOT NULL,
    "candidate_id" TEXT NOT NULL,
    "department_id" TEXT,
    "applied_datetime" TIMESTAMP(3) NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,
    "programme_sessionId" TEXT,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "feedback_question" (
    "id" TEXT NOT NULL,
    "question" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,
    "type" "question_type" NOT NULL,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "feedback_option" (
    "id" TEXT NOT NULL,
    "text" TEXT,
    "value" INTEGER,
    "feedback_question_id" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "session_feedBack" (
    "id" TEXT NOT NULL,
    "feedback_question_id" TEXT NOT NULL,
    "answer" TEXT,
    "option_value" TEXT,
    "feedback_option_id" TEXT,
    "programme_session_id" TEXT NOT NULL,
    "programme_candidate_id" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "session_attendance" (
    "id" TEXT NOT NULL,
    "selfie_url" TEXT NOT NULL,
    "programme_candidate_id" TEXT NOT NULL,
    "programme_session_id" TEXT NOT NULL,
    "created_date_time" TIMESTAMP(3) NOT NULL,
    "is_absent" BOOLEAN NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "programme_feedback" (
    "id" TEXT NOT NULL,
    "feedback_question_id" TEXT NOT NULL,
    "answer" TEXT,
    "option_value" TEXT,
    "feedback_option_id" TEXT,
    "programme_id" TEXT NOT NULL,
    "programme_candidate_id" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL DEFAULT false,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "programme_feedback_question" (
    "id" TEXT NOT NULL,
    "programme_id" TEXT NOT NULL,
    "feedback_question_id" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL,
    "programme_masterId" TEXT,

    PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "programme_session_feedback_question" (
    "id" TEXT NOT NULL,
    "programme_session_id" TEXT NOT NULL,
    "feedback_question_id" TEXT NOT NULL,
    "is_deleted" BOOLEAN NOT NULL,
    "programme_session_masterId" TEXT,

    PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "api_module.name_unique" ON "api_module"("name");

-- CreateIndex
CREATE INDEX "api_module_main_index" ON "api_module"("id", "is_deleted");

-- CreateIndex
CREATE UNIQUE INDEX "role.name_unique" ON "role"("name");

-- CreateIndex
CREATE INDEX "role_main_index" ON "role"("id", "is_deleted");

-- CreateIndex
CREATE UNIQUE INDEX "ui_module.name_unique" ON "ui_module"("name");

-- CreateIndex
CREATE INDEX "ui_module_main_index" ON "ui_module"("id", "is_deleted");

-- CreateIndex
CREATE INDEX "ui_module_component_main_index" ON "ui_module_component"("ui_module_id", "is_deleted");

-- CreateIndex
CREATE UNIQUE INDEX "ui_module_component_Name_uiModuleId_unique" ON "ui_module_component"("name", "ui_module_id");

-- CreateIndex
CREATE INDEX "ui_module_component_api_module_main_index" ON "ui_module_component_api_module"("ui_module_component_id");

-- CreateIndex
CREATE INDEX "ui_module_component_role_access_role_index" ON "ui_module_component_role_access"("role_id");

-- CreateIndex
CREATE INDEX "ui_module_component_role_access_ui_module_component_role_index" ON "ui_module_component_role_access"("ui_module_component_id", "role_id");

-- CreateIndex
CREATE UNIQUE INDEX "ui_module_component_role_access_unique" ON "ui_module_component_role_access"("ui_module_component_id", "role_id");

-- CreateIndex
CREATE INDEX "ui_module_role_access_role_index" ON "ui_module_role_access"("role_id");

-- CreateIndex
CREATE INDEX "ui_module_role_access_ui_module_role_index" ON "ui_module_role_access"("ui_module_id", "role_id");

-- CreateIndex
CREATE UNIQUE INDEX "ui_module_role_access_unique" ON "ui_module_role_access"("ui_module_id", "role_id");

-- CreateIndex
CREATE INDEX "audit_log_table_item_index" ON "audit_log"("table_name", "item_id");

-- CreateIndex
CREATE UNIQUE INDEX "user.username_unique" ON "user"("username");

-- CreateIndex
CREATE INDEX "user_role_role_index" ON "user_role"("role_id");

-- CreateIndex
CREATE INDEX "user_role_user_index" ON "user_role"("user_id");

-- CreateIndex
CREATE UNIQUE INDEX "state.name_unique" ON "state"("name");

-- CreateIndex
CREATE UNIQUE INDEX "district.name_unique" ON "district"("name");

-- CreateIndex
CREATE INDEX "state_district_index" ON "district"("state_id");

-- CreateIndex
CREATE UNIQUE INDEX "department.name_unique" ON "department"("name");

-- CreateIndex
CREATE INDEX "parent_department_department_index" ON "department"("parent_department_id");

-- CreateIndex
CREATE UNIQUE INDEX "faculty.mobile_unique" ON "faculty"("mobile");

-- CreateIndex
CREATE UNIQUE INDEX "course_director.mobile_unique" ON "course_director"("mobile");

-- CreateIndex
CREATE UNIQUE INDEX "data_entry_operator.mobile_unique" ON "data_entry_operator"("mobile");

-- CreateIndex
CREATE UNIQUE INDEX "programme.rtc_district_id_unique" ON "programme"("rtc_district_id");

-- CreateIndex
CREATE UNIQUE INDEX "programme_session.qr_code_unique" ON "programme_session"("qr_code");

-- CreateIndex
CREATE UNIQUE INDEX "officer.name_unique" ON "officer"("name");

-- CreateIndex
CREATE UNIQUE INDEX "candidate.name_unique" ON "candidate"("name");

-- CreateIndex
CREATE UNIQUE INDEX "feedback_question.question_unique" ON "feedback_question"("question");

-- AddForeignKey
ALTER TABLE "ui_module_component" ADD FOREIGN KEY ("ui_module_id") REFERENCES "ui_module"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ui_module_component_api_module" ADD FOREIGN KEY ("api_module_id") REFERENCES "api_module"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ui_module_component_api_module" ADD FOREIGN KEY ("ui_module_component_id") REFERENCES "ui_module_component"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ui_module_component_role_access" ADD FOREIGN KEY ("role_id") REFERENCES "role"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ui_module_component_role_access" ADD FOREIGN KEY ("ui_module_component_id") REFERENCES "ui_module_component"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ui_module_role_access" ADD FOREIGN KEY ("role_id") REFERENCES "role"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ui_module_role_access" ADD FOREIGN KEY ("ui_module_id") REFERENCES "ui_module"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user" ADD FOREIGN KEY ("districtId") REFERENCES "district"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_role" ADD FOREIGN KEY ("role_id") REFERENCES "role"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_role" ADD FOREIGN KEY ("user_id") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "district" ADD FOREIGN KEY ("state_id") REFERENCES "state"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "department" ADD FOREIGN KEY ("parent_department_id") REFERENCES "department"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "department" ADD FOREIGN KEY ("district_id") REFERENCES "district"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "faculty" ADD FOREIGN KEY ("user_id") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "course_director" ADD FOREIGN KEY ("user_id") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "data_entry_operator" ADD FOREIGN KEY ("user_id") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme_master" ADD FOREIGN KEY ("course_director_id") REFERENCES "course_director"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme_master" ADD FOREIGN KEY ("department_id") REFERENCES "department"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme_session_master" ADD FOREIGN KEY ("programme_master_id") REFERENCES "programme_master"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme" ADD FOREIGN KEY ("programme_master_id") REFERENCES "programme_master"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme" ADD FOREIGN KEY ("rtc_district_id") REFERENCES "rtc_district"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme" ADD FOREIGN KEY ("regional_training_center_id") REFERENCES "regional_training_center"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme" ADD FOREIGN KEY ("programme_department_id") REFERENCES "programme_department"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme" ADD FOREIGN KEY ("rtc_locationId") REFERENCES "rtc_location"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "rtc_district" ADD FOREIGN KEY ("regional_training_center_id") REFERENCES "regional_training_center"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "rtc_district" ADD FOREIGN KEY ("district_id") REFERENCES "district"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "rtc_district" ADD FOREIGN KEY ("rtc_locationId") REFERENCES "rtc_location"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme_department" ADD FOREIGN KEY ("department_id") REFERENCES "department"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme_session" ADD FOREIGN KEY ("faculty_id") REFERENCES "faculty"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme_session" ADD FOREIGN KEY ("programme_id") REFERENCES "programme"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme_session" ADD FOREIGN KEY ("programme_session_master_id") REFERENCES "programme_session_master"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme_call_letter" ADD FOREIGN KEY ("programme_id") REFERENCES "programme"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme_rescheduledate" ADD FOREIGN KEY ("programme_id") REFERENCES "programme"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme_rescheduledate" ADD FOREIGN KEY ("rescheduled_by_id") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "hostel_block" ADD FOREIGN KEY ("hostel_building_id") REFERENCES "hostel_building"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "hostel_floor" ADD FOREIGN KEY ("hostel_block_id") REFERENCES "hostel_block"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "hostel_room" ADD FOREIGN KEY ("hostel_floor_id") REFERENCES "hostel_floor"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "hostel_bed" ADD FOREIGN KEY ("hostel_room_id") REFERENCES "hostel_room"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "hostel_room_checkin" ADD FOREIGN KEY ("hostel_bed_id") REFERENCES "hostel_bed"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "hostel_room_checkin" ADD FOREIGN KEY ("programme_candidate_id") REFERENCES "programme_candidate"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "officer" ADD FOREIGN KEY ("user_id") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "candidate" ADD FOREIGN KEY ("department_id") REFERENCES "department"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme_candidate" ADD FOREIGN KEY ("candidate_id") REFERENCES "candidate"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme_candidate" ADD FOREIGN KEY ("programme_id") REFERENCES "programme"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme_candidate" ADD FOREIGN KEY ("department_id") REFERENCES "department"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme_candidate" ADD FOREIGN KEY ("programme_sessionId") REFERENCES "programme_session"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "feedback_option" ADD FOREIGN KEY ("feedback_question_id") REFERENCES "feedback_question"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "session_feedBack" ADD FOREIGN KEY ("programme_candidate_id") REFERENCES "programme_candidate"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "session_feedBack" ADD FOREIGN KEY ("programme_session_id") REFERENCES "programme_session"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "session_feedBack" ADD FOREIGN KEY ("feedback_question_id") REFERENCES "feedback_question"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "session_feedBack" ADD FOREIGN KEY ("feedback_option_id") REFERENCES "feedback_option"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "session_attendance" ADD FOREIGN KEY ("programme_candidate_id") REFERENCES "programme_candidate"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "session_attendance" ADD FOREIGN KEY ("programme_session_id") REFERENCES "programme_session"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme_feedback" ADD FOREIGN KEY ("programme_candidate_id") REFERENCES "programme_candidate"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme_feedback" ADD FOREIGN KEY ("programme_id") REFERENCES "programme"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme_feedback" ADD FOREIGN KEY ("feedback_question_id") REFERENCES "feedback_question"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme_feedback" ADD FOREIGN KEY ("feedback_option_id") REFERENCES "feedback_option"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme_feedback_question" ADD FOREIGN KEY ("programme_id") REFERENCES "programme"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme_feedback_question" ADD FOREIGN KEY ("feedback_question_id") REFERENCES "feedback_question"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme_feedback_question" ADD FOREIGN KEY ("programme_masterId") REFERENCES "programme_master"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme_session_feedback_question" ADD FOREIGN KEY ("programme_session_id") REFERENCES "programme_session"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme_session_feedback_question" ADD FOREIGN KEY ("feedback_question_id") REFERENCES "feedback_question"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "programme_session_feedback_question" ADD FOREIGN KEY ("programme_session_masterId") REFERENCES "programme_session_master"("id") ON DELETE SET NULL ON UPDATE CASCADE;
