-- CreateExtension
CREATE EXTENSION IF NOT EXISTS "vector";

-- CreateEnum
CREATE TYPE "UserRole" AS ENUM ('super_admin', 'company_admin', 'admin', 'user');

-- CreateEnum
CREATE TYPE "Gender" AS ENUM ('male', 'female', 'others');

-- CreateEnum
CREATE TYPE "RecipientType" AS ENUM ('tag', 'user_id', 'custom');

-- CreateEnum
CREATE TYPE "ApproverType" AS ENUM ('tag', 'user_id', 'role_id');

-- CreateEnum
CREATE TYPE "NotifyType" AS ENUM ('email', 'push');

-- CreateEnum
CREATE TYPE "ClauseType" AS ENUM ('where', 'having');

-- CreateEnum
CREATE TYPE "sendMailType" AS ENUM ('cc', 'bcc');

-- CreateEnum
CREATE TYPE "ReportType" AS ENUM ('lcp', 'powerbi');

-- CreateEnum
CREATE TYPE "aboutType" AS ENUM ('lcp', 'project');

-- CreateEnum
CREATE TYPE "ApprovalStatus" AS ENUM ('pending', 'approval_needed', 'approval_completed', 'approval_rejected', 'void');

-- CreateEnum
CREATE TYPE "ProcessStatus" AS ENUM ('under_approval', 'approved', 'rejected', 'submitted', 'created', 'not_appear');

-- CreateEnum
CREATE TYPE "NotificationType" AS ENUM ('email', 'sms', 'whatsapp');

-- CreateEnum
CREATE TYPE "TemplateType" AS ENUM ('xlsx', 'pdf');

-- CreateEnum
CREATE TYPE "PageSize" AS ENUM ('A0', 'A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'LETTER', 'LEGAL', 'TABLOID', 'EXECUTIVE');

-- CreateEnum
CREATE TYPE "Orientation" AS ENUM ('portrait', 'landscape');

-- CreateEnum
CREATE TYPE "ColorTheme" AS ENUM ('light', 'dark', 'corporate', 'classic', 'minimal', 'modern', 'vibrant', 'monochrome', 'custom');

-- CreateEnum
CREATE TYPE "FontFamily" AS ENUM ('Helvetica', 'Arial', 'TimesNewRoman', 'CourierNew', 'Georgia', 'Verdana', 'Tahoma', 'TrebuchetMS', 'PalatinoLinotype', 'LucidaConsole', 'Roboto', 'OpenSans', 'Lato', 'Poppins', 'Inter', 'Montserrat', 'Nunito', 'SourceSansPro', 'Raleway', 'Merriweather', 'Ubuntu');

-- CreateEnum
CREATE TYPE "WatermarkPosition" AS ENUM ('center', 'diagonal', 'top_left', 'top_right', 'bottom_left', 'bottom_right', 'full_background');

-- CreateEnum
CREATE TYPE "OtpType" AS ENUM ('email', 'sms', 'whatsapp');

-- CreateEnum
CREATE TYPE "LoginStatus" AS ENUM ('SUCCESS', 'FAILED', 'LOCKED');

-- CreateTable
CREATE TABLE "users" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "username" VARCHAR(100) NOT NULL,
    "email" VARCHAR(100) NOT NULL,
    "email_verified" BOOLEAN NOT NULL DEFAULT false,
    "password" VARCHAR(255),
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "role" "UserRole" NOT NULL DEFAULT 'user',
    "process_status" "ProcessStatus" NOT NULL DEFAULT 'submitted',
    "is_drafted" BOOLEAN NOT NULL DEFAULT false,
    "reason" TEXT,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_at" TIMESTAMPTZ,
    "last_login" TIMESTAMPTZ,
    "last_login_device" VARCHAR(100),
    "allow_login_web" INTEGER NOT NULL DEFAULT 1,
    "allow_login_mobile" INTEGER NOT NULL DEFAULT 1,

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

-- CreateTable
CREATE TABLE "user_details" (
    "id" SERIAL NOT NULL,
    "user_id" INTEGER NOT NULL,
    "code" VARCHAR(100) NOT NULL,
    "first_name" VARCHAR(100) NOT NULL,
    "last_name" VARCHAR(100),
    "designation_id" INTEGER,
    "department_id" INTEGER,
    "profile_pic" VARCHAR(255),
    "dob" DATE,
    "country_code" VARCHAR(100),
    "phone_number" VARCHAR(100),
    "gender" "Gender" NOT NULL DEFAULT 'male',
    "user_time_zone" VARCHAR(100),
    "address" VARCHAR(255),
    "culture" VARCHAR(100),
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "designations" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "code" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "departments" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "code" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "department_head_id" INTEGER,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "request_logs" (
    "id" BIGSERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "user_id" INTEGER,
    "req_method" VARCHAR(100),
    "req_url" VARCHAR(255),
    "req_body" TEXT,
    "res_status" BOOLEAN NOT NULL DEFAULT false,
    "res_code" INTEGER NOT NULL DEFAULT 500,
    "res_message" TEXT,
    "req_response" TEXT,
    "req_headers" TEXT,
    "req_ip" VARCHAR(255),
    "req_device" VARCHAR(255),
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "financial_years" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "code" VARCHAR(100) NOT NULL,
    "is_freezed" BOOLEAN NOT NULL DEFAULT false,
    "start_date" TIMESTAMPTZ NOT NULL,
    "end_date" TIMESTAMPTZ NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "document_sequences" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "module_name" VARCHAR(100) NOT NULL,
    "financial_year_id" INTEGER,
    "current_sequence_no" INTEGER NOT NULL DEFAULT 0,
    "start_sequence_no" INTEGER NOT NULL DEFAULT 0,
    "end_sequence_no" INTEGER NOT NULL DEFAULT 0,
    "sequence_length" INTEGER NOT NULL DEFAULT 9,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "code_format" VARCHAR(100),
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "audit_logs" (
    "id" SERIAL NOT NULL,
    "operation_type" VARCHAR(10) NOT NULL,
    "table_name" VARCHAR(100) NOT NULL,
    "field_name" VARCHAR(100) NOT NULL,
    "old_value" TEXT,
    "new_value" TEXT,
    "entity_id" INTEGER NOT NULL,
    "user_id" INTEGER,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "permissions" (
    "id" SERIAL NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "slug" VARCHAR(100) NOT NULL,
    "entity_id" INTEGER,
    "order_no" DECIMAL(4,2) NOT NULL DEFAULT 0,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "roles" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "role_permissions" (
    "role_id" INTEGER NOT NULL,
    "permission_id" INTEGER NOT NULL,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "role_permissions_pkey" PRIMARY KEY ("company_id","role_id","permission_id")
);

-- CreateTable
CREATE TABLE "user_roles" (
    "user_id" INTEGER NOT NULL,
    "role_id" INTEGER NOT NULL,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "user_roles_pkey" PRIMARY KEY ("company_id","user_id","role_id")
);

-- CreateTable
CREATE TABLE "user_permissions" (
    "user_id" INTEGER NOT NULL,
    "permission_id" INTEGER NOT NULL,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "user_permissions_pkey" PRIMARY KEY ("company_id","user_id","permission_id")
);

-- CreateTable
CREATE TABLE "otps" (
    "id" SERIAL NOT NULL,
    "user_id" INTEGER NOT NULL,
    "otp" VARCHAR(8) NOT NULL,
    "type" "OtpType" NOT NULL DEFAULT 'email',
    "notification_template_process_slug" VARCHAR(100) NOT NULL,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "verified_at" TIMESTAMP(3),

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

-- CreateTable
CREATE TABLE "languages" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "name_in_english" VARCHAR(100),
    "flag" VARCHAR(10),
    "code" VARCHAR(10),
    "rtl" BOOLEAN NOT NULL DEFAULT false,
    "description" TEXT NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "language_contents" (
    "id" SERIAL NOT NULL,
    "language_id" INTEGER NOT NULL DEFAULT 1,
    "key_content" VARCHAR(100) NOT NULL,
    "values" VARCHAR(100) NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "menu" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "slug" VARCHAR(255),
    "description" VARCHAR(100),
    "menu_type" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "menu_items" (
    "id" SERIAL NOT NULL,
    "menu_id" INTEGER NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "target" VARCHAR(255),
    "parent_id" INTEGER,
    "permission_id" INTEGER,
    "entity_id" INTEGER,
    "link_type" INTEGER,
    "order_no" DECIMAL(4,2) NOT NULL DEFAULT 0,
    "menu_img" VARCHAR(255),
    "short_cut_keys" VARCHAR(255),
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "action_types" (
    "id" SERIAL NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "description" VARCHAR(255) NOT NULL,
    "company_id" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "entity_types" (
    "id" SERIAL NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "slug" VARCHAR(100) NOT NULL,
    "description" VARCHAR(255) NOT NULL,
    "company_id" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "wizard_group" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "slug" VARCHAR(100),
    "description" VARCHAR(100),
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "company_id" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "wizard_types" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "description" VARCHAR(100),
    "company_id" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "about_lcp" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "type" "aboutType" NOT NULL DEFAULT 'lcp',
    "name" VARCHAR(255) NOT NULL,
    "description" TEXT,
    "order_no" DECIMAL(4,2) DEFAULT 0,
    "documentation_video_url" TEXT,
    "documentation_pdf" TEXT,
    "documentation_word" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "master_entities" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "entity_name" VARCHAR(100) NOT NULL,
    "entity_type" VARCHAR(100) NOT NULL,
    "report_type" "ReportType" NOT NULL DEFAULT 'lcp',
    "primary_table" VARCHAR(100),
    "is_admin_module" BOOLEAN NOT NULL DEFAULT false,
    "draft_mode" BOOLEAN NOT NULL DEFAULT false,
    "associated_tables" JSONB,
    "query_information" JSONB,
    "form_information" JSONB,
    "report_information" JSONB,
    "add_query_information" JSONB,
    "edit_query_information" JSONB,
    "preset_query_information" JSONB,
    "static_page_content" TEXT,
    "export_template_id" INTEGER,
    "dashboard_wizard_group_id" INTEGER,
    "dashboard_wizard_type" VARCHAR(100),
    "dashboard_wizard_rows" INTEGER,
    "dashboard_wizard_columns" INTEGER,
    "dashboard_wizard_order_no" DECIMAL(4,2) DEFAULT 0,
    "dashboard_wizard_options" JSONB,
    "dashboard_grid" TEXT,
    "reload_timeout" INTEGER,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "master_entity_line_items" (
    "id" SERIAL NOT NULL,
    "master_grid_id" INTEGER NOT NULL,
    "field_name" TEXT NOT NULL,
    "display_name" VARCHAR(100) NOT NULL,
    "field_html_content" TEXT,
    "enum_values" JSONB,
    "order_no" DECIMAL(4,2) NOT NULL DEFAULT 0,
    "is_grid_column" BOOLEAN NOT NULL DEFAULT true,
    "is_searchable" BOOLEAN NOT NULL DEFAULT true,
    "clause_type" "ClauseType" NOT NULL DEFAULT 'where',
    "is_sortable" BOOLEAN NOT NULL DEFAULT true,
    "field_type_id" INTEGER NOT NULL,
    "link_type" VARCHAR(100) NOT NULL DEFAULT 'none',
    "link_action" VARCHAR(100),
    "link_mode" VARCHAR(100) NOT NULL DEFAULT 'none',
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "field_types" (
    "id" SERIAL NOT NULL,
    "field_type" VARCHAR(100) NOT NULL,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "menu_types" (
    "id" SERIAL NOT NULL,
    "name" VARCHAR(100),
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "notification_template_process" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "slug" VARCHAR(100) NOT NULL,
    "query_information" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "notification_type" "NotificationType" NOT NULL DEFAULT 'email',

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

-- CreateTable
CREATE TABLE "notification_template_tags" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "slug" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100),
    "description" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "notification_template_recipient_tags" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "slug" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100),
    "notification_type" "NotificationType" NOT NULL DEFAULT 'email',
    "description" TEXT,
    "query_information" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "notification_template_process_tags_mapping" (
    "notification_template_process_id" INTEGER NOT NULL,
    "notification_template_tag_id" INTEGER NOT NULL,
    "company_id" INTEGER NOT NULL,

    CONSTRAINT "notification_template_process_tags_mapping_pkey" PRIMARY KEY ("notification_template_process_id","notification_template_tag_id","company_id")
);

-- CreateTable
CREATE TABLE "notification_templates" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "slug" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "email_subject" VARCHAR(255),
    "message" TEXT,
    "components" JSONB,
    "parameter_format" VARCHAR(100),
    "category" TEXT,
    "language" VARCHAR(100),
    "email_body" TEXT,
    "notification_template_process_id" INTEGER NOT NULL,
    "notification_type" "NotificationType" NOT NULL DEFAULT 'email',
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "created_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "deleted_by" INTEGER,
    "company_id" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "notification_template_assignments" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "notification_template_process_id" INTEGER NOT NULL,
    "template_id" INTEGER NOT NULL,
    "recipient_type" "RecipientType" NOT NULL DEFAULT 'tag',
    "notification_to" VARCHAR(100),
    "notification_type" "NotificationType" NOT NULL DEFAULT 'email',
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "created_by" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "email_template_cc_bcc" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "send_type" "sendMailType" NOT NULL DEFAULT 'cc',
    "recipient_type" "RecipientType" NOT NULL DEFAULT 'tag',
    "email_to" VARCHAR(100),
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "created_by" INTEGER NOT NULL,
    "email_template_assignment_id" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "notification_process_jobs" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "notification_template_process_slug" VARCHAR(100) NOT NULL,
    "unique_id" VARCHAR(100) NOT NULL,
    "user_id" INTEGER NOT NULL,
    "prefill_data" TEXT,
    "attachments_path" TEXT,
    "attachments_name" TEXT,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "notification_type" "NotificationType" NOT NULL DEFAULT 'email',
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "created_by" INTEGER,

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

-- CreateTable
CREATE TABLE "notification_jobs" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "process_slug" VARCHAR(100) NOT NULL,
    "notification_to" TEXT,
    "notification_subject" VARCHAR(100),
    "notification_content" TEXT,
    "attachments_path" TEXT,
    "attachments_name" TEXT,
    "notification_cc" VARCHAR(100),
    "notification_bcc" VARCHAR(100),
    "notification_type_id" VARCHAR(10) NOT NULL,
    "notification_status_id" VARCHAR(10) NOT NULL,
    "notification_type" "NotificationType" NOT NULL DEFAULT 'email',
    "whatsapp_notification_data" JSONB,
    "last_attempt_message" TEXT,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "parent_id" INTEGER NOT NULL DEFAULT 0,
    "no_of_attempts" INTEGER NOT NULL DEFAULT 0,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "created_by" INTEGER,
    "sent_at" TIMESTAMPTZ,
    "read_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "carousel_templates" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "slug" VARCHAR(100) NOT NULL,
    "description" VARCHAR(100),
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "carousel_template_line_items" (
    "id" SERIAL NOT NULL,
    "carousel_template_id" INTEGER NOT NULL,
    "name" TEXT NOT NULL,
    "slug" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "image_url" TEXT,
    "video_url" TEXT,
    "clickable_link" TEXT,
    "order_no" DECIMAL(4,2) NOT NULL DEFAULT 0,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "import_templates" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "slug" VARCHAR(100) NOT NULL,
    "description" VARCHAR(100),
    "max_row_count" INTEGER NOT NULL DEFAULT 500,
    "header_row" INTEGER NOT NULL DEFAULT 0,
    "data_start_row" INTEGER NOT NULL DEFAULT 0,
    "data_end_row" INTEGER NOT NULL DEFAULT 0,
    "ignore_error_rows" BOOLEAN NOT NULL DEFAULT false,
    "is_admin_module" BOOLEAN NOT NULL DEFAULT false,
    "is_send_mail" BOOLEAN NOT NULL DEFAULT false,
    "email_process_slug" VARCHAR(255),
    "job_type" TEXT DEFAULT 'direct',
    "batch_process_count" INTEGER DEFAULT 50,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "import_template_line_items" (
    "id" SERIAL NOT NULL,
    "import_template_id" INTEGER NOT NULL,
    "field_name" VARCHAR(255) NOT NULL,
    "display_name" VARCHAR(100) NOT NULL,
    "field_table" VARCHAR(100) NOT NULL,
    "order_no" DECIMAL(4,2) NOT NULL DEFAULT 0,
    "width" INTEGER DEFAULT 0,
    "default_value" VARCHAR(100),
    "check_reg_exp" VARCHAR(255),
    "is_nullable" BOOLEAN NOT NULL DEFAULT true,
    "is_unique" BOOLEAN NOT NULL DEFAULT false,
    "is_foreign" BOOLEAN NOT NULL DEFAULT false,
    "unique_query" TEXT,
    "foreign_query" TEXT,
    "is_enum" BOOLEAN NOT NULL DEFAULT false,
    "is_multiple" BOOLEAN NOT NULL DEFAULT false,
    "enum_values" VARCHAR(100),
    "expression_rules" JSONB,
    "query_rules" JSONB,
    "foreign_table" VARCHAR(100),
    "foreign_column" VARCHAR(100),
    "foreign_can_create" BOOLEAN NOT NULL DEFAULT false,
    "is_individual" BOOLEAN NOT NULL DEFAULT false,
    "individual_column" VARCHAR(20),
    "field_type_id" INTEGER,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "import_template_queries" (
    "id" SERIAL NOT NULL,
    "import_template_id" INTEGER NOT NULL,
    "query_string" TEXT,
    "query_name" VARCHAR(255) NOT NULL,
    "allow_multiple" BOOLEAN NOT NULL DEFAULT false,
    "is_individual" BOOLEAN NOT NULL DEFAULT false,
    "before_lineitems" BOOLEAN NOT NULL DEFAULT true,
    "order_no" DECIMAL(4,2) NOT NULL DEFAULT 0,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "direct_import_details" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "import_template_id" INTEGER,
    "file_path" TEXT,
    "file_name" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "import_jobs" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "import_template_id" INTEGER,
    "name" VARCHAR(100) NOT NULL,
    "description" VARCHAR(100),
    "sequence_number" VARCHAR(255),
    "ignore_error_rows" BOOLEAN NOT NULL DEFAULT false,
    "header_details" JSONB,
    "table_config" JSONB,
    "total_rows" INTEGER NOT NULL DEFAULT 0,
    "completed_rows" INTEGER NOT NULL DEFAULT 0,
    "error_rows" INTEGER NOT NULL DEFAULT 0,
    "batch_process_count" INTEGER DEFAULT 50,
    "job_status" TEXT DEFAULT 'created',
    "last_processed_row_id" INTEGER DEFAULT 0,
    "file_path" TEXT,
    "file_name" TEXT,
    "validation_started_at" TIMESTAMP(3),
    "validation_completed_at" TIMESTAMP(3),
    "processing_started_at" TIMESTAMP(3),
    "processing_completed_at" TIMESTAMP(3),
    "expected_completion_time" TIMESTAMP(3),
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "import_job_line_items" (
    "id" SERIAL NOT NULL,
    "import_job_id" INTEGER NOT NULL,
    "row_object" JSONB,
    "job_status" TEXT DEFAULT 'created',
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "validated_at" TIMESTAMP(3),
    "processed_at" TIMESTAMP(3),

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

-- CreateTable
CREATE TABLE "export_templates" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "slug" VARCHAR(100) NOT NULL,
    "description" VARCHAR(100),
    "max_row_count" INTEGER NOT NULL DEFAULT 500,
    "header_row" INTEGER NOT NULL DEFAULT 0,
    "data_start_row" INTEGER NOT NULL DEFAULT 0,
    "data_end_row" INTEGER NOT NULL DEFAULT 0,
    "data_filepath" TEXT,
    "template_type" "TemplateType" NOT NULL DEFAULT 'xlsx',
    "pdf_configurations" JSONB,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "export_template_line_items" (
    "id" SERIAL NOT NULL,
    "export_template_id" INTEGER NOT NULL,
    "field_name" VARCHAR(255) NOT NULL,
    "display_name" VARCHAR(100) NOT NULL,
    "field_table" VARCHAR(100) NOT NULL,
    "order_no" DECIMAL(4,2) NOT NULL DEFAULT 0,
    "default_value" VARCHAR(100),
    "column_name" VARCHAR(255),
    "is_individual" BOOLEAN NOT NULL DEFAULT false,
    "individual_column" VARCHAR(20),
    "field_type_id" INTEGER,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "export_template_queries" (
    "id" SERIAL NOT NULL,
    "export_template_id" INTEGER NOT NULL,
    "query_string" TEXT,
    "query_name" VARCHAR(255) NOT NULL,
    "query_procedure" TEXT NOT NULL DEFAULT 'procedure',
    "is_individual" BOOLEAN NOT NULL DEFAULT false,
    "order_no" DECIMAL(4,2) NOT NULL DEFAULT 0,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "statuses" (
    "id" SERIAL NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "slug" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "status_id" INTEGER DEFAULT 1,

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

-- CreateTable
CREATE TABLE "app_category_types" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "category_type_id" VARCHAR(10) NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "description" VARCHAR(255),
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "app_categories" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "category_type_id" VARCHAR(10) NOT NULL,
    "category_id" VARCHAR(10) NOT NULL,
    "parent_id" VARCHAR(10),
    "name" VARCHAR(100) NOT NULL,
    "description" VARCHAR(255),
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "app_configurations" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "order_no" DECIMAL(4,2) NOT NULL DEFAULT 0,
    "config_key" VARCHAR(100) NOT NULL,
    "category_id" VARCHAR(10) NOT NULL,
    "category_type_id" VARCHAR(10),
    "config_select_json" JSONB,
    "config_file_value" TEXT,
    "config_value_type" VARCHAR(100) NOT NULL,
    "config_field_type" VARCHAR(100) NOT NULL,
    "display_config" BOOLEAN NOT NULL DEFAULT true,
    "config_value" TEXT,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "app_user_configurations" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "order_no" DECIMAL(4,2) NOT NULL DEFAULT 0,
    "config_key" VARCHAR(100) NOT NULL,
    "category_id" VARCHAR(10) NOT NULL,
    "category_type_id" VARCHAR(10),
    "config_select_json" JSONB,
    "config_file_value" TEXT,
    "config_value_type" VARCHAR(100) NOT NULL,
    "config_field_type" VARCHAR(100) NOT NULL,
    "display_config" BOOLEAN NOT NULL DEFAULT true,
    "config_value" TEXT,
    "user_id" INTEGER NOT NULL,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "file_upload_logs" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "doc_name" VARCHAR(255),
    "org_name" VARCHAR(255),
    "extension" VARCHAR(100),
    "description" VARCHAR(100),
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "data_transfer_queries" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "select_query" TEXT NOT NULL,
    "insert_query" TEXT NOT NULL,
    "transfer_type" TEXT NOT NULL,
    "job_name" TEXT NOT NULL,
    "destination_table" TEXT NOT NULL,
    "clear_destination_table" BOOLEAN NOT NULL,
    "execution_order" INTEGER NOT NULL,
    "command_type" TEXT NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER,
    "created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
    "company_id" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "device_registration" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "company_id" INTEGER NOT NULL,
    "device_name" VARCHAR(255) NOT NULL,
    "device_unique_id" VARCHAR(255) NOT NULL,
    "user_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "policies" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "company_id" INTEGER NOT NULL,
    "slug" VARCHAR(225) NOT NULL,
    "name" VARCHAR(255) NOT NULL,
    "description" TEXT NOT NULL,
    "query_information" JSONB,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "user_policies" (
    "company_id" INTEGER NOT NULL,
    "policy_id" INTEGER NOT NULL,
    "user_id" INTEGER NOT NULL
);

-- CreateTable
CREATE TABLE "role_policies" (
    "company_id" INTEGER NOT NULL,
    "policy_id" INTEGER NOT NULL,
    "role_id" INTEGER NOT NULL
);

-- CreateTable
CREATE TABLE "app_versions" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "company_id" INTEGER NOT NULL,
    "type" VARCHAR(50) NOT NULL,
    "version_type" VARCHAR(225) NOT NULL,
    "version" VARCHAR(255) NOT NULL,
    "description" TEXT NOT NULL,
    "is_frontend_changed" BOOLEAN NOT NULL DEFAULT false,
    "is_backend_changed" BOOLEAN NOT NULL DEFAULT false,
    "is_database_changed" BOOLEAN NOT NULL DEFAULT false,
    "developed_by" VARCHAR(255),
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "scheduled_jobs" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "timing" VARCHAR(100) NOT NULL DEFAULT '* * * * *',
    "cron_url" TEXT,
    "concat_base_url" BOOLEAN NOT NULL DEFAULT true,
    "downloadables" TEXT,
    "description" TEXT,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "company_id" INTEGER NOT NULL DEFAULT 1,
    "status_id" INTEGER NOT NULL DEFAULT 1,

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

-- CreateTable
CREATE TABLE "scheduled_job_logs" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "scheduled_job_id" INTEGER NOT NULL,
    "executed_statement" TEXT,
    "schedule_status" TEXT,
    "downloadables" TEXT,
    "response" TEXT,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "company_id" INTEGER NOT NULL DEFAULT 1,
    "status_id" INTEGER NOT NULL DEFAULT 1,

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

-- CreateTable
CREATE TABLE "approval_workflows" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "slug" VARCHAR(100) NOT NULL,
    "query_information" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "url" TEXT,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "approval_workflow_approver_tags" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "slug" VARCHAR(100) NOT NULL,
    "name" VARCHAR(100),
    "description" TEXT,
    "query_information" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "approval_workflow_assignments" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "approval_workflow_slug" TEXT NOT NULL,
    "approver_order_no" DECIMAL(4,2) NOT NULL DEFAULT 0,
    "approver_type" "ApproverType" NOT NULL DEFAULT 'tag',
    "approver" VARCHAR(255),
    "approve_query_information" TEXT[],
    "reject_query_information" TEXT[],
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "approve_mail_id" INTEGER,
    "reject_mail_id" INTEGER,
    "approve_whatsapp_id" INTEGER,
    "reject_whatsapp_id" INTEGER,

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

-- CreateTable
CREATE TABLE "approval_process_jobs" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "approval_workflow_slug" VARCHAR(100) NOT NULL,
    "sequence_no" VARCHAR(100) NOT NULL,
    "description" VARCHAR(100),
    "primary_table" VARCHAR(100),
    "unique_id" INTEGER,
    "screen_id" TEXT NOT NULL,
    "user_id" INTEGER,
    "prefill_data" TEXT,
    "details" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "approval_process_job_workflows" (
    "id" SERIAL NOT NULL,
    "approval_workflow_assignment_id" INTEGER NOT NULL,
    "approval_process_job_id" TEXT NOT NULL,
    "approval_workflow_slug" VARCHAR(100) NOT NULL,
    "approval_process_job_name" VARCHAR(100),
    "approval_process_job_description" TEXT,
    "approve_query_information" TEXT[],
    "reject_query_information" TEXT[],
    "primary_table" VARCHAR(100),
    "sequence_no" VARCHAR(100) NOT NULL,
    "unique_id" INTEGER,
    "user_id" INTEGER,
    "screen_id" TEXT NOT NULL,
    "prefill_data" TEXT,
    "url" TEXT,
    "approver_order_no" DECIMAL(4,2) NOT NULL DEFAULT 0,
    "approver_type" "ApproverType" NOT NULL DEFAULT 'tag',
    "approver" VARCHAR(255),
    "review_status" "ApprovalStatus" NOT NULL DEFAULT 'pending',
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "reviewed_by" INTEGER,
    "reason" TEXT,
    "approve_mail_id" INTEGER,
    "reject_mail_id" INTEGER,
    "approve_whatsapp_id" INTEGER,
    "reject_whatsapp_id" INTEGER,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "assigned_at" TIMESTAMPTZ,
    "processed_at" TIMESTAMPTZ,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "details" TEXT,

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

-- CreateTable
CREATE TABLE "approval_process_job_workflow_users" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "approval_process_job_workflow_id" INTEGER NOT NULL,
    "user_id" INTEGER,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "delegations" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "user_id" INTEGER NOT NULL,
    "delegated_user_id" INTEGER NOT NULL,
    "reason" TEXT,
    "start_date" TIMESTAMPTZ NOT NULL,
    "end_date" TIMESTAMPTZ NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "schema_chunks" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "table_name" TEXT NOT NULL,
    "chunk" TEXT NOT NULL,
    "embedding" vector(1536),
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "embedding_vector_logs" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "user_id" INTEGER,
    "cost" DECIMAL(10,6) NOT NULL,
    "company_id" INTEGER NOT NULL,
    "table_name" TEXT NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "openai_usage_logs" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "user_id" INTEGER,
    "prompt" TEXT NOT NULL,
    "generated_sql" TEXT NOT NULL,
    "prompt_tokens" INTEGER NOT NULL,
    "completion_tokens" INTEGER NOT NULL,
    "total_tokens" INTEGER NOT NULL,
    "cost" DECIMAL(10,6) NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "query_execution_logs" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "query" TEXT NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "child_processes" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" TEXT NOT NULL,
    "slug" VARCHAR(100) NOT NULL,
    "description" TEXT,
    "downloadables" TEXT,
    "command" TEXT NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "child_process_logs" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "child_process_id" INTEGER NOT NULL,
    "process_status" TEXT,
    "downloadables" TEXT,
    "output" TEXT NOT NULL,
    "initiated_by" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "themes" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "name" VARCHAR(100) NOT NULL,
    "description" VARCHAR(255),
    "reference_images" VARCHAR,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "theme_line_items" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "theme_id" INTEGER NOT NULL,
    "attribute" VARCHAR NOT NULL,
    "value" VARCHAR,
    "description" VARCHAR(255),
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "theme_attributes" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "attribute" VARCHAR(100) NOT NULL,
    "value" VARCHAR(100),
    "description" VARCHAR(255),
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "barcode_templates" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "company_id" INTEGER NOT NULL,
    "prefix" VARCHAR(255) NOT NULL,
    "label_start" VARCHAR(255) NOT NULL,
    "label_end" VARCHAR(255) NOT NULL,
    "name" VARCHAR(255) NOT NULL,
    "page_width" INTEGER NOT NULL,
    "page_height" INTEGER NOT NULL,
    "zpl_code" TEXT NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_by" INTEGER,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_by" INTEGER,
    "deleted_at" TIMESTAMPTZ,

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

-- CreateTable
CREATE TABLE "user_login_histories" (
    "id" SERIAL NOT NULL,
    "user_id" INTEGER NOT NULL,
    "session_id" TEXT,
    "login_time" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "logout_time" TIMESTAMP(3),
    "ip_address" INET,
    "user_agent" TEXT,
    "login_status" "LoginStatus" NOT NULL DEFAULT 'SUCCESS',
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "failure_reason" TEXT,
    "created_by" INTEGER,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_at" TIMESTAMPTZ,
    "company_id" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "phone_country_codes" (
    "id" SERIAL NOT NULL,
    "uuid" UUID NOT NULL DEFAULT uuid_generate_v4(),
    "country_code" VARCHAR(10) NOT NULL,
    "iso_code" VARCHAR(10) NOT NULL,
    "country_name" VARCHAR(100) NOT NULL,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,

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

-- CreateIndex
CREATE UNIQUE INDEX "users_company_id_uuid_key" ON "users"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "users_company_id_email_role_key" ON "users"("company_id", "email", "role");

-- CreateIndex
CREATE UNIQUE INDEX "users_company_id_username_key" ON "users"("company_id", "username");

-- CreateIndex
CREATE UNIQUE INDEX "users_company_id_id_key" ON "users"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "user_details_company_id_user_id_key" ON "user_details"("company_id", "user_id");

-- CreateIndex
CREATE UNIQUE INDEX "user_details_company_id_code_key" ON "user_details"("company_id", "code");

-- CreateIndex
CREATE UNIQUE INDEX "designations_company_id_id_key" ON "designations"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "designations_company_id_uuid_key" ON "designations"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "designations_company_id_code_key" ON "designations"("company_id", "code");

-- CreateIndex
CREATE UNIQUE INDEX "departments_company_id_id_key" ON "departments"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "departments_company_id_uuid_key" ON "departments"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "departments_company_id_code_key" ON "departments"("company_id", "code");

-- CreateIndex
CREATE INDEX "request_logs_company_id_idx" ON "request_logs"("company_id");

-- CreateIndex
CREATE UNIQUE INDEX "financial_years_company_id_id_key" ON "financial_years"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "financial_years_company_id_uuid_key" ON "financial_years"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "financial_years_company_id_code_key" ON "financial_years"("company_id", "code");

-- CreateIndex
CREATE UNIQUE INDEX "document_sequences_company_id_id_key" ON "document_sequences"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "document_sequences_company_id_uuid_key" ON "document_sequences"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "document_sequences_company_id_financial_year_id_module_name_key" ON "document_sequences"("company_id", "financial_year_id", "module_name");

-- CreateIndex
CREATE UNIQUE INDEX "audit_logs_company_id_id_key" ON "audit_logs"("company_id", "id");

-- CreateIndex
CREATE INDEX "permissions_company_id_order_no_idx" ON "permissions"("company_id", "order_no");

-- CreateIndex
CREATE UNIQUE INDEX "permissions_company_id_slug_key" ON "permissions"("company_id", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "permissions_company_id_id_key" ON "permissions"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "roles_company_id_id_key" ON "roles"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "roles_company_id_uuid_key" ON "roles"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "roles_company_id_name_key" ON "roles"("company_id", "name");

-- CreateIndex
CREATE INDEX "otps_company_id_user_id_notification_template_process_slug_idx" ON "otps"("company_id", "user_id", "notification_template_process_slug");

-- CreateIndex
CREATE UNIQUE INDEX "languages_company_id_id_key" ON "languages"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "languages_company_id_uuid_key" ON "languages"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "languages_company_id_code_key" ON "languages"("company_id", "code");

-- CreateIndex
CREATE UNIQUE INDEX "language_contents_company_id_id_key" ON "language_contents"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "menu_company_id_id_key" ON "menu"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "menu_company_id_uuid_key" ON "menu"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "menu_items_company_id_id_key" ON "menu_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "menu_items_company_id_menu_id_name_key" ON "menu_items"("company_id", "menu_id", "name");

-- CreateIndex
CREATE UNIQUE INDEX "action_types_company_id_id_key" ON "action_types"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "entity_types_company_id_id_key" ON "entity_types"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "wizard_group_company_id_id_key" ON "wizard_group"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "wizard_group_company_id_slug_key" ON "wizard_group"("company_id", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "wizard_types_company_id_id_key" ON "wizard_types"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "wizard_types_company_id_name_key" ON "wizard_types"("company_id", "name");

-- CreateIndex
CREATE UNIQUE INDEX "about_lcp_company_id_id_key" ON "about_lcp"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "master_entities_company_id_id_key" ON "master_entities"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "master_entities_company_id_entity_name_key" ON "master_entities"("company_id", "entity_name");

-- CreateIndex
CREATE UNIQUE INDEX "master_entity_line_items_company_id_id_key" ON "master_entity_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "master_entity_line_items_company_id_master_grid_id_field_na_key" ON "master_entity_line_items"("company_id", "master_grid_id", "field_name", "display_name");

-- CreateIndex
CREATE UNIQUE INDEX "field_types_company_id_id_key" ON "field_types"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "menu_types_company_id_id_key" ON "menu_types"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "notification_template_process_company_id_id_key" ON "notification_template_process"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "notification_template_process_company_id_slug_key" ON "notification_template_process"("company_id", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "notification_template_process_company_id_slug_notification__key" ON "notification_template_process"("company_id", "slug", "notification_type");

-- CreateIndex
CREATE UNIQUE INDEX "notification_template_tags_company_id_id_key" ON "notification_template_tags"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "notification_template_tags_company_id_slug_key" ON "notification_template_tags"("company_id", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "notification_template_recipient_tags_company_id_id_key" ON "notification_template_recipient_tags"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "notification_template_recipient_tags_company_id_slug_key" ON "notification_template_recipient_tags"("company_id", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "notification_template_recipient_tags_company_id_slug_notifi_key" ON "notification_template_recipient_tags"("company_id", "slug", "notification_type");

-- CreateIndex
CREATE UNIQUE INDEX "notification_templates_company_id_id_key" ON "notification_templates"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "notification_templates_company_id_slug_key" ON "notification_templates"("company_id", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "notification_templates_company_id_slug_notification_type_key" ON "notification_templates"("company_id", "slug", "notification_type");

-- CreateIndex
CREATE UNIQUE INDEX "notification_template_assignments_id_key" ON "notification_template_assignments"("id");

-- CreateIndex
CREATE UNIQUE INDEX "email_template_cc_bcc_email_template_assignment_id_send_typ_key" ON "email_template_cc_bcc"("email_template_assignment_id", "send_type", "recipient_type", "email_to");

-- CreateIndex
CREATE UNIQUE INDEX "carousel_templates_company_id_id_key" ON "carousel_templates"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "carousel_templates_company_id_slug_key" ON "carousel_templates"("company_id", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "carousel_template_line_items_company_id_id_key" ON "carousel_template_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "carousel_template_line_items_company_id_carousel_template_i_key" ON "carousel_template_line_items"("company_id", "carousel_template_id", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "import_templates_company_id_id_key" ON "import_templates"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "import_templates_company_id_slug_key" ON "import_templates"("company_id", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "import_template_line_items_company_id_id_key" ON "import_template_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "import_template_line_items_company_id_import_template_id_fi_key" ON "import_template_line_items"("company_id", "import_template_id", "field_table", "field_name");

-- CreateIndex
CREATE UNIQUE INDEX "import_template_line_items_company_id_import_template_id_di_key" ON "import_template_line_items"("company_id", "import_template_id", "display_name");

-- CreateIndex
CREATE UNIQUE INDEX "import_template_queries_company_id_id_key" ON "import_template_queries"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "direct_import_details_company_id_id_key" ON "direct_import_details"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "import_jobs_company_id_id_key" ON "import_jobs"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "import_job_line_items_company_id_id_key" ON "import_job_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "export_templates_company_id_id_key" ON "export_templates"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "export_templates_company_id_slug_key" ON "export_templates"("company_id", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "export_template_line_items_company_id_id_key" ON "export_template_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "export_template_line_items_company_id_export_template_id_fi_key" ON "export_template_line_items"("company_id", "export_template_id", "field_table", "field_name");

-- CreateIndex
CREATE UNIQUE INDEX "export_template_line_items_company_id_export_template_id_di_key" ON "export_template_line_items"("company_id", "export_template_id", "display_name");

-- CreateIndex
CREATE UNIQUE INDEX "export_template_queries_company_id_id_key" ON "export_template_queries"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "statuses_id_key" ON "statuses"("id");

-- CreateIndex
CREATE UNIQUE INDEX "statuses_slug_key" ON "statuses"("slug");

-- CreateIndex
CREATE UNIQUE INDEX "app_category_types_category_type_id_key" ON "app_category_types"("category_type_id");

-- CreateIndex
CREATE UNIQUE INDEX "app_category_types_company_id_category_type_id_key" ON "app_category_types"("company_id", "category_type_id");

-- CreateIndex
CREATE UNIQUE INDEX "app_category_types_company_id_id_key" ON "app_category_types"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "app_category_types_company_id_name_key" ON "app_category_types"("company_id", "name");

-- CreateIndex
CREATE UNIQUE INDEX "app_categories_company_id_category_type_id_category_id_key" ON "app_categories"("company_id", "category_type_id", "category_id");

-- CreateIndex
CREATE UNIQUE INDEX "app_categories_company_id_category_type_id_category_id_name_key" ON "app_categories"("company_id", "category_type_id", "category_id", "name");

-- CreateIndex
CREATE UNIQUE INDEX "app_categories_company_id_id_key" ON "app_categories"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "app_configurations_company_id_id_key" ON "app_configurations"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "app_configurations_company_id_config_key_key" ON "app_configurations"("company_id", "config_key");

-- CreateIndex
CREATE UNIQUE INDEX "app_user_configurations_company_id_id_key" ON "app_user_configurations"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "app_user_configurations_company_id_config_key_user_id_key" ON "app_user_configurations"("company_id", "config_key", "user_id");

-- CreateIndex
CREATE UNIQUE INDEX "file_upload_logs_company_id_id_key" ON "file_upload_logs"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "data_transfer_queries_company_id_id_key" ON "data_transfer_queries"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "device_registration_company_id_id_key" ON "device_registration"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "device_registration_company_id_uuid_key" ON "device_registration"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "policies_company_id_id_key" ON "policies"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "policies_company_id_uuid_key" ON "policies"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "policies_company_id_name_key" ON "policies"("company_id", "name");

-- CreateIndex
CREATE UNIQUE INDEX "policies_company_id_slug_key" ON "policies"("company_id", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "user_policies_company_id_policy_id_user_id_key" ON "user_policies"("company_id", "policy_id", "user_id");

-- CreateIndex
CREATE UNIQUE INDEX "role_policies_company_id_policy_id_role_id_key" ON "role_policies"("company_id", "policy_id", "role_id");

-- CreateIndex
CREATE UNIQUE INDEX "app_versions_company_id_id_key" ON "app_versions"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "app_versions_company_id_uuid_key" ON "app_versions"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "scheduled_job_logs_company_id_id_key" ON "scheduled_job_logs"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "approval_workflows_company_id_id_key" ON "approval_workflows"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "approval_workflows_company_id_slug_key" ON "approval_workflows"("company_id", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "approval_workflow_approver_tags_company_id_id_key" ON "approval_workflow_approver_tags"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "approval_workflow_approver_tags_company_id_slug_key" ON "approval_workflow_approver_tags"("company_id", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "approval_workflow_assignments_company_id_id_key" ON "approval_workflow_assignments"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "approval_workflow_assignments_company_id_uuid_key" ON "approval_workflow_assignments"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "approval_workflow_assignments_company_id_approval_workflow__key" ON "approval_workflow_assignments"("company_id", "approval_workflow_slug", "approver_order_no");

-- CreateIndex
CREATE UNIQUE INDEX "approval_process_jobs_company_id_uuid_key" ON "approval_process_jobs"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "approval_process_jobs_company_id_id_key" ON "approval_process_jobs"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "approval_process_job_workflows_company_id_id_key" ON "approval_process_job_workflows"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "approval_process_job_workflow_users_company_id_id_key" ON "approval_process_job_workflow_users"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "approval_process_job_workflow_users_company_id_uuid_key" ON "approval_process_job_workflow_users"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "delegations_company_id_id_key" ON "delegations"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "delegations_company_id_uuid_key" ON "delegations"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "schema_chunks_table_name_key" ON "schema_chunks"("table_name");

-- CreateIndex
CREATE UNIQUE INDEX "child_processes_company_id_id_key" ON "child_processes"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "child_processes_company_id_uuid_key" ON "child_processes"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "child_processes_company_id_slug_key" ON "child_processes"("company_id", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "child_process_logs_company_id_id_key" ON "child_process_logs"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "child_process_logs_company_id_uuid_key" ON "child_process_logs"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "themes_company_id_id_key" ON "themes"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "themes_company_id_uuid_key" ON "themes"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "themes_company_id_name_key" ON "themes"("company_id", "name");

-- CreateIndex
CREATE UNIQUE INDEX "theme_line_items_company_id_id_key" ON "theme_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "theme_line_items_company_id_uuid_key" ON "theme_line_items"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "theme_attributes_company_id_id_key" ON "theme_attributes"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "theme_attributes_company_id_uuid_key" ON "theme_attributes"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "barcode_templates_company_id_id_key" ON "barcode_templates"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "barcode_templates_company_id_uuid_key" ON "barcode_templates"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "user_login_histories_company_id_id_key" ON "user_login_histories"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "user_login_histories_user_id_login_time_key" ON "user_login_histories"("user_id", "login_time");

-- AddForeignKey
ALTER TABLE "users" ADD CONSTRAINT "users_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "users" ADD CONSTRAINT "users_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "users" ADD CONSTRAINT "users_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "users" ADD CONSTRAINT "users_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_details" ADD CONSTRAINT "user_details_company_id_designation_id_fkey" FOREIGN KEY ("company_id", "designation_id") REFERENCES "designations"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_details" ADD CONSTRAINT "user_details_company_id_department_id_fkey" FOREIGN KEY ("company_id", "department_id") REFERENCES "departments"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_details" ADD CONSTRAINT "user_details_company_id_user_id_fkey" FOREIGN KEY ("company_id", "user_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_details" ADD CONSTRAINT "user_details_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_details" ADD CONSTRAINT "user_details_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_details" ADD CONSTRAINT "user_details_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "designations" ADD CONSTRAINT "designations_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "designations" ADD CONSTRAINT "designations_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "designations" ADD CONSTRAINT "designations_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "designations" ADD CONSTRAINT "designations_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "departments" ADD CONSTRAINT "departments_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "departments" ADD CONSTRAINT "departments_company_id_department_head_id_fkey" FOREIGN KEY ("company_id", "department_head_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "departments" ADD CONSTRAINT "departments_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "departments" ADD CONSTRAINT "departments_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "departments" ADD CONSTRAINT "departments_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "request_logs" ADD CONSTRAINT "request_logs_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "request_logs" ADD CONSTRAINT "request_logs_company_id_user_id_fkey" FOREIGN KEY ("company_id", "user_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "financial_years" ADD CONSTRAINT "financial_years_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "financial_years" ADD CONSTRAINT "financial_years_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "financial_years" ADD CONSTRAINT "financial_years_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "financial_years" ADD CONSTRAINT "financial_years_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "document_sequences" ADD CONSTRAINT "document_sequences_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "document_sequences" ADD CONSTRAINT "document_sequences_company_id_financial_year_id_fkey" FOREIGN KEY ("company_id", "financial_year_id") REFERENCES "financial_years"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "document_sequences" ADD CONSTRAINT "document_sequences_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "document_sequences" ADD CONSTRAINT "document_sequences_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "document_sequences" ADD CONSTRAINT "document_sequences_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "audit_logs" ADD CONSTRAINT "audit_logs_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE "permissions" ADD CONSTRAINT "permissions_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "permissions" ADD CONSTRAINT "permissions_company_id_entity_id_fkey" FOREIGN KEY ("company_id", "entity_id") REFERENCES "master_entities"("company_id", "id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "roles" ADD CONSTRAINT "roles_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "roles" ADD CONSTRAINT "roles_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "roles" ADD CONSTRAINT "roles_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "roles" ADD CONSTRAINT "roles_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "role_permissions" ADD CONSTRAINT "role_permissions_company_id_role_id_fkey" FOREIGN KEY ("company_id", "role_id") REFERENCES "roles"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "role_permissions" ADD CONSTRAINT "role_permissions_company_id_permission_id_fkey" FOREIGN KEY ("company_id", "permission_id") REFERENCES "permissions"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_roles" ADD CONSTRAINT "user_roles_company_id_user_id_fkey" FOREIGN KEY ("company_id", "user_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_roles" ADD CONSTRAINT "user_roles_company_id_role_id_fkey" FOREIGN KEY ("company_id", "role_id") REFERENCES "roles"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_permissions" ADD CONSTRAINT "user_permissions_company_id_user_id_fkey" FOREIGN KEY ("company_id", "user_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_permissions" ADD CONSTRAINT "user_permissions_company_id_permission_id_fkey" FOREIGN KEY ("company_id", "permission_id") REFERENCES "permissions"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "otps" ADD CONSTRAINT "otps_company_id_user_id_fkey" FOREIGN KEY ("company_id", "user_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "languages" ADD CONSTRAINT "languages_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "languages" ADD CONSTRAINT "languages_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "languages" ADD CONSTRAINT "languages_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "languages" ADD CONSTRAINT "languages_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "language_contents" ADD CONSTRAINT "language_contents_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "language_contents" ADD CONSTRAINT "language_contents_company_id_language_id_fkey" FOREIGN KEY ("company_id", "language_id") REFERENCES "languages"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "menu" ADD CONSTRAINT "menu_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "menu" ADD CONSTRAINT "menu_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "menu" ADD CONSTRAINT "menu_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "menu" ADD CONSTRAINT "menu_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "menu_items" ADD CONSTRAINT "menu_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "menu_items" ADD CONSTRAINT "menu_items_company_id_menu_id_fkey" FOREIGN KEY ("company_id", "menu_id") REFERENCES "menu"("company_id", "id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "menu_items" ADD CONSTRAINT "menu_items_company_id_entity_id_fkey" FOREIGN KEY ("company_id", "entity_id") REFERENCES "master_entities"("company_id", "id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "menu_items" ADD CONSTRAINT "menu_items_company_id_permission_id_fkey" FOREIGN KEY ("company_id", "permission_id") REFERENCES "permissions"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "menu_items" ADD CONSTRAINT "menu_items_company_id_parent_id_fkey" FOREIGN KEY ("company_id", "parent_id") REFERENCES "menu_items"("company_id", "id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "menu_items" ADD CONSTRAINT "menu_items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "menu_items" ADD CONSTRAINT "menu_items_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "menu_items" ADD CONSTRAINT "menu_items_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "about_lcp" ADD CONSTRAINT "about_lcp_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "master_entities" ADD CONSTRAINT "master_entities_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "master_entity_line_items" ADD CONSTRAINT "master_entity_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "master_entity_line_items" ADD CONSTRAINT "master_entity_line_items_company_id_master_grid_id_fkey" FOREIGN KEY ("company_id", "master_grid_id") REFERENCES "master_entities"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "master_entity_line_items" ADD CONSTRAINT "master_entity_line_items_company_id_field_type_id_fkey" FOREIGN KEY ("company_id", "field_type_id") REFERENCES "field_types"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "field_types" ADD CONSTRAINT "field_types_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "menu_types" ADD CONSTRAINT "menu_types_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notification_template_process" ADD CONSTRAINT "notification_template_process_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notification_template_tags" ADD CONSTRAINT "notification_template_tags_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notification_template_recipient_tags" ADD CONSTRAINT "notification_template_recipient_tags_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notification_template_process_tags_mapping" ADD CONSTRAINT "fk_ntp_tags_mapping_process" FOREIGN KEY ("notification_template_process_id", "company_id") REFERENCES "notification_template_process"("id", "company_id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notification_template_process_tags_mapping" ADD CONSTRAINT "fk_ntp_tags_mapping_tag" FOREIGN KEY ("notification_template_tag_id", "company_id") REFERENCES "notification_template_tags"("id", "company_id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notification_templates" ADD CONSTRAINT "notification_templates_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notification_templates" ADD CONSTRAINT "notification_templates_notification_template_process_id_co_fkey" FOREIGN KEY ("notification_template_process_id", "company_id") REFERENCES "notification_template_process"("id", "company_id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notification_templates" ADD CONSTRAINT "notification_templates_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notification_templates" ADD CONSTRAINT "notification_templates_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notification_templates" ADD CONSTRAINT "notification_templates_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notification_template_assignments" ADD CONSTRAINT "notification_template_assignments_notification_template_pr_fkey" FOREIGN KEY ("notification_template_process_id", "company_id") REFERENCES "notification_template_process"("id", "company_id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notification_template_assignments" ADD CONSTRAINT "notification_template_assignments_template_id_company_id_fkey" FOREIGN KEY ("template_id", "company_id") REFERENCES "notification_templates"("id", "company_id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notification_template_assignments" ADD CONSTRAINT "notification_template_assignments_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "email_template_cc_bcc" ADD CONSTRAINT "email_template_cc_bcc_email_template_assignment_id_fkey" FOREIGN KEY ("email_template_assignment_id") REFERENCES "notification_template_assignments"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notification_process_jobs" ADD CONSTRAINT "notification_process_jobs_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notification_process_jobs" ADD CONSTRAINT "notification_process_jobs_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notification_jobs" ADD CONSTRAINT "notification_jobs_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notification_jobs" ADD CONSTRAINT "notification_jobs_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "carousel_templates" ADD CONSTRAINT "carousel_templates_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "carousel_templates" ADD CONSTRAINT "carousel_templates_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "carousel_templates" ADD CONSTRAINT "carousel_templates_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "carousel_templates" ADD CONSTRAINT "carousel_templates_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "carousel_template_line_items" ADD CONSTRAINT "carousel_template_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "carousel_template_line_items" ADD CONSTRAINT "carousel_template_line_items_company_id_carousel_template__fkey" FOREIGN KEY ("company_id", "carousel_template_id") REFERENCES "carousel_templates"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "import_templates" ADD CONSTRAINT "import_templates_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "import_templates" ADD CONSTRAINT "import_templates_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "import_templates" ADD CONSTRAINT "import_templates_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "import_templates" ADD CONSTRAINT "import_templates_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "import_template_line_items" ADD CONSTRAINT "import_template_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "import_template_line_items" ADD CONSTRAINT "import_template_line_items_company_id_import_template_id_fkey" FOREIGN KEY ("company_id", "import_template_id") REFERENCES "import_templates"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "import_template_line_items" ADD CONSTRAINT "import_template_line_items_company_id_field_type_id_fkey" FOREIGN KEY ("company_id", "field_type_id") REFERENCES "field_types"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "import_template_queries" ADD CONSTRAINT "import_template_queries_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "import_template_queries" ADD CONSTRAINT "import_template_queries_company_id_import_template_id_fkey" FOREIGN KEY ("company_id", "import_template_id") REFERENCES "import_templates"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "direct_import_details" ADD CONSTRAINT "direct_import_details_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "direct_import_details" ADD CONSTRAINT "direct_import_details_company_id_import_template_id_fkey" FOREIGN KEY ("company_id", "import_template_id") REFERENCES "import_templates"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "direct_import_details" ADD CONSTRAINT "direct_import_details_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "direct_import_details" ADD CONSTRAINT "direct_import_details_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "direct_import_details" ADD CONSTRAINT "direct_import_details_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "import_jobs" ADD CONSTRAINT "import_jobs_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "import_jobs" ADD CONSTRAINT "import_jobs_company_id_import_template_id_fkey" FOREIGN KEY ("company_id", "import_template_id") REFERENCES "import_templates"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "import_jobs" ADD CONSTRAINT "import_jobs_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "import_jobs" ADD CONSTRAINT "import_jobs_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "import_jobs" ADD CONSTRAINT "import_jobs_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "import_job_line_items" ADD CONSTRAINT "import_job_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "import_job_line_items" ADD CONSTRAINT "import_job_line_items_company_id_import_job_id_fkey" FOREIGN KEY ("company_id", "import_job_id") REFERENCES "import_jobs"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "export_templates" ADD CONSTRAINT "export_templates_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "export_templates" ADD CONSTRAINT "export_templates_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "export_templates" ADD CONSTRAINT "export_templates_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "export_templates" ADD CONSTRAINT "export_templates_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "export_template_line_items" ADD CONSTRAINT "export_template_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "export_template_line_items" ADD CONSTRAINT "export_template_line_items_company_id_export_template_id_fkey" FOREIGN KEY ("company_id", "export_template_id") REFERENCES "export_templates"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "export_template_line_items" ADD CONSTRAINT "export_template_line_items_company_id_field_type_id_fkey" FOREIGN KEY ("company_id", "field_type_id") REFERENCES "field_types"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "export_template_queries" ADD CONSTRAINT "export_template_queries_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "export_template_queries" ADD CONSTRAINT "export_template_queries_company_id_export_template_id_fkey" FOREIGN KEY ("company_id", "export_template_id") REFERENCES "export_templates"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "statuses" ADD CONSTRAINT "statuses_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "app_category_types" ADD CONSTRAINT "app_category_types_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "app_category_types" ADD CONSTRAINT "app_category_types_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "app_category_types" ADD CONSTRAINT "app_category_types_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "app_categories" ADD CONSTRAINT "app_categories_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "app_categories" ADD CONSTRAINT "app_categories_category_type_id_company_id_fkey" FOREIGN KEY ("category_type_id", "company_id") REFERENCES "app_category_types"("category_type_id", "company_id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "app_categories" ADD CONSTRAINT "app_categories_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "app_categories" ADD CONSTRAINT "app_categories_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "app_categories" ADD CONSTRAINT "app_categories_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "app_configurations" ADD CONSTRAINT "app_configurations_category_id_category_type_id_company_id_fkey" FOREIGN KEY ("category_id", "category_type_id", "company_id") REFERENCES "app_categories"("category_id", "category_type_id", "company_id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "app_configurations" ADD CONSTRAINT "app_configurations_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "app_configurations" ADD CONSTRAINT "app_configurations_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "app_configurations" ADD CONSTRAINT "app_configurations_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "app_user_configurations" ADD CONSTRAINT "app_user_configurations_category_id_category_type_id_compa_fkey" FOREIGN KEY ("category_id", "category_type_id", "company_id") REFERENCES "app_categories"("category_id", "category_type_id", "company_id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "app_user_configurations" ADD CONSTRAINT "app_user_configurations_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "app_user_configurations" ADD CONSTRAINT "app_user_configurations_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "app_user_configurations" ADD CONSTRAINT "app_user_configurations_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "file_upload_logs" ADD CONSTRAINT "file_upload_logs_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "device_registration" ADD CONSTRAINT "device_registration_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "device_registration" ADD CONSTRAINT "device_registration_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "device_registration" ADD CONSTRAINT "device_registration_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "device_registration" ADD CONSTRAINT "device_registration_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "device_registration" ADD CONSTRAINT "device_registration_company_id_user_id_fkey" FOREIGN KEY ("company_id", "user_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "policies" ADD CONSTRAINT "policies_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "policies" ADD CONSTRAINT "policies_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "policies" ADD CONSTRAINT "policies_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "policies" ADD CONSTRAINT "policies_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_policies" ADD CONSTRAINT "user_policies_company_id_policy_id_fkey" FOREIGN KEY ("company_id", "policy_id") REFERENCES "policies"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_policies" ADD CONSTRAINT "user_policies_company_id_user_id_fkey" FOREIGN KEY ("company_id", "user_id") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "role_policies" ADD CONSTRAINT "role_policies_company_id_policy_id_fkey" FOREIGN KEY ("company_id", "policy_id") REFERENCES "policies"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "role_policies" ADD CONSTRAINT "role_policies_company_id_role_id_fkey" FOREIGN KEY ("company_id", "role_id") REFERENCES "roles"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "app_versions" ADD CONSTRAINT "app_versions_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "app_versions" ADD CONSTRAINT "app_versions_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "app_versions" ADD CONSTRAINT "app_versions_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "app_versions" ADD CONSTRAINT "app_versions_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "scheduled_jobs" ADD CONSTRAINT "scheduled_jobs_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "scheduled_job_logs" ADD CONSTRAINT "scheduled_job_logs_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "scheduled_job_logs" ADD CONSTRAINT "scheduled_job_logs_scheduled_job_id_fkey" FOREIGN KEY ("scheduled_job_id") REFERENCES "scheduled_jobs"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approval_workflows" ADD CONSTRAINT "approval_workflows_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approval_workflow_approver_tags" ADD CONSTRAINT "approval_workflow_approver_tags_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approval_workflow_assignments" ADD CONSTRAINT "approval_workflow_assignments_company_id_approval_workflow_fkey" FOREIGN KEY ("company_id", "approval_workflow_slug") REFERENCES "approval_workflows"("company_id", "slug") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approval_workflow_assignments" ADD CONSTRAINT "approval_workflow_assignments_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approval_workflow_assignments" ADD CONSTRAINT "approve_mail_fkey" FOREIGN KEY ("approve_mail_id") REFERENCES "notification_templates"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approval_workflow_assignments" ADD CONSTRAINT "reject_mail_fkey" FOREIGN KEY ("reject_mail_id") REFERENCES "notification_templates"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approval_workflow_assignments" ADD CONSTRAINT "approve_whatsapp_fkey" FOREIGN KEY ("approve_whatsapp_id") REFERENCES "notification_templates"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approval_workflow_assignments" ADD CONSTRAINT "reject_whatsapp_fkey" FOREIGN KEY ("reject_whatsapp_id") REFERENCES "notification_templates"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approval_process_jobs" ADD CONSTRAINT "approval_process_jobs_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approval_process_job_workflows" ADD CONSTRAINT "approval_process_job_workflows_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approval_process_job_workflow_users" ADD CONSTRAINT "approval_process_job_workflow_users_company_id_approval_pr_fkey" FOREIGN KEY ("company_id", "approval_process_job_workflow_id") REFERENCES "approval_process_job_workflows"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "approval_process_job_workflow_users" ADD CONSTRAINT "approval_process_job_workflow_users_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "delegations" ADD CONSTRAINT "delegations_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "schema_chunks" ADD CONSTRAINT "schema_chunks_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "embedding_vector_logs" ADD CONSTRAINT "embedding_vector_logs_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "openai_usage_logs" ADD CONSTRAINT "openai_usage_logs_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "query_execution_logs" ADD CONSTRAINT "query_execution_logs_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "child_processes" ADD CONSTRAINT "child_processes_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "child_process_logs" ADD CONSTRAINT "child_process_logs_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "child_process_logs" ADD CONSTRAINT "child_process_logs_company_id_child_process_id_fkey" FOREIGN KEY ("company_id", "child_process_id") REFERENCES "child_processes"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "child_process_logs" ADD CONSTRAINT "child_process_logs_company_id_initiated_by_fkey" FOREIGN KEY ("company_id", "initiated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "themes" ADD CONSTRAINT "themes_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "themes" ADD CONSTRAINT "themes_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "themes" ADD CONSTRAINT "themes_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "themes" ADD CONSTRAINT "themes_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "theme_line_items" ADD CONSTRAINT "theme_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "theme_line_items" ADD CONSTRAINT "theme_line_items_company_id_theme_id_fkey" FOREIGN KEY ("company_id", "theme_id") REFERENCES "themes"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "theme_line_items" ADD CONSTRAINT "theme_line_items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "theme_line_items" ADD CONSTRAINT "theme_line_items_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "theme_line_items" ADD CONSTRAINT "theme_line_items_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "theme_attributes" ADD CONSTRAINT "theme_attributes_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "theme_attributes" ADD CONSTRAINT "theme_attributes_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "theme_attributes" ADD CONSTRAINT "theme_attributes_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "theme_attributes" ADD CONSTRAINT "theme_attributes_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "barcode_templates" ADD CONSTRAINT "barcode_templates_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "barcode_templates" ADD CONSTRAINT "barcode_templates_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "barcode_templates" ADD CONSTRAINT "barcode_templates_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "barcode_templates" ADD CONSTRAINT "barcode_templates_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users"("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_login_histories" ADD CONSTRAINT "user_login_histories_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "user_login_histories" ADD CONSTRAINT "user_login_histories_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

