-- CreateTable
CREATE TABLE "statuses" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "name" TEXT NOT NULL,
    "slug" TEXT NOT NULL,
    "description" TEXT,
    "status_id" INTEGER DEFAULT 1
);

-- CreateTable
CREATE TABLE "action_types" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "name" TEXT NOT NULL,
    "description" TEXT NOT NULL,
    "company_id" INTEGER NOT NULL
);

-- CreateTable
CREATE TABLE "entity_types" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "name" TEXT NOT NULL,
    "slug" TEXT NOT NULL,
    "description" TEXT NOT NULL,
    "company_id" INTEGER NOT NULL
);

-- CreateTable
CREATE TABLE "field_types" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "field_type" TEXT NOT NULL,
    "company_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_at" TEXT NOT NULL DEFAULT (datetime('now')),
    CONSTRAINT "field_types_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "otps" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "user_id" INTEGER NOT NULL,
    "otp" TEXT NOT NULL,
    "purpose" TEXT NOT NULL,
    "company_id" INTEGER NOT NULL,
    "created_at" TEXT NOT NULL DEFAULT (datetime('now')),
    CONSTRAINT "otps_company_id_user_id_fkey" FOREIGN KEY ("company_id", "user_id") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "languages" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "name_in_english" TEXT,
    "flag" TEXT,
    "code" TEXT,
    "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 NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TEXT NOT NULL DEFAULT (datetime('now')),
    "updated_at" DATETIME,
    "deleted_at" DATETIME,
    CONSTRAINT "languages_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "languages_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "languages_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "languages_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "language_contents" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "language_id" INTEGER NOT NULL DEFAULT 1,
    "key_content" TEXT NOT NULL,
    "values" TEXT NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TEXT NOT NULL DEFAULT (datetime('now')),
    CONSTRAINT "language_contents_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    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
);

-- CreateTable
CREATE TABLE "webservice_logs" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" BIGINT NOT NULL PRIMARY KEY,
    "salesman_id" INTEGER,
    "req_method" TEXT,
    "service_type" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "app_version" TEXT,
    "parameters" TEXT,
    "time_taken_to_complete" INTEGER,
    "response" TEXT,
    "device_imei" TEXT,
    "company_id" INTEGER NOT NULL,
    "created_at" TEXT NOT NULL DEFAULT (datetime('now')),
    CONSTRAINT "webservice_logs_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "webservice_logs_company_id_salesman_id_fkey" FOREIGN KEY ("company_id", "salesman_id") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "wizard_types" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT NOT NULL,
    "company_id" INTEGER NOT NULL
);

-- CreateTable
CREATE TABLE "wizard_group" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "slug" TEXT NOT NULL,
    "description" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_at" TEXT NOT NULL DEFAULT (datetime('now')),
    "company_id" INTEGER NOT NULL
);

-- CreateTable
CREATE TABLE "roles" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "name" TEXT 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" TEXT NOT NULL DEFAULT (datetime('now')),
    "updated_at" DATETIME,
    "deleted_at" DATETIME,
    CONSTRAINT "roles_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "roles_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "roles_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "roles_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "users" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "username" TEXT NOT NULL,
    "email" TEXT NOT NULL,
    "email_verified" BOOLEAN NOT NULL DEFAULT false,
    "password" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "role" TEXT NOT NULL DEFAULT 'user',
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TEXT NOT NULL DEFAULT (datetime('now')),
    "updated_at" DATETIME,
    "deleted_at" DATETIME,
    "last_login" DATETIME,
    "last_login_device" TEXT,
    CONSTRAINT "users_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "users_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "users_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "users_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "user_details" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "user_id" INTEGER NOT NULL,
    "code" TEXT NOT NULL,
    "first_name" TEXT NOT NULL,
    "last_name" TEXT,
    "designation_id" INTEGER,
    "department_id" INTEGER,
    "profile_pic" TEXT,
    "dob" DATETIME,
    "country_code" TEXT,
    "phone_number" TEXT,
    "gender" TEXT DEFAULT 'male',
    "user_time_zone" TEXT,
    "address" TEXT,
    "culture" TEXT,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TEXT NOT NULL DEFAULT (datetime('now')),
    "updated_at" DATETIME,
    "deleted_at" DATETIME,
    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,
    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,
    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,
    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,
    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,
    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
);

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

    PRIMARY KEY ("company_id", "user_id", "role_id"),
    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,
    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
);

-- CreateTable
CREATE TABLE "master_entities" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "entity_name" TEXT NOT NULL,
    "entity_type" TEXT NOT NULL,
    "primary_table" TEXT,
    "associated_tables" TEXT,
    "query_information" TEXT,
    "form_information" TEXT,
    "add_query_information" TEXT,
    "edit_query_information" TEXT,
    "preset_query_information" TEXT,
    "static_page_content" TEXT,
    "dashboard_wizard_group_id" INTEGER,
    "dashboard_wizard_type" TEXT,
    "dashboard_wizard_rows" INTEGER,
    "dashboard_wizard_columns" INTEGER,
    "dashboard_wizard_order_no" DECIMAL DEFAULT 0,
    "dashboard_wizard_options" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TEXT NOT NULL DEFAULT (datetime('now')),
    "deleted_at" DATETIME,
    CONSTRAINT "master_entities_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "master_entity_line_items" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "master_grid_id" INTEGER NOT NULL,
    "field_name" TEXT NOT NULL,
    "display_name" TEXT NOT NULL,
    "width" INTEGER DEFAULT 0,
    "format" TEXT,
    "is_default" BOOLEAN NOT NULL DEFAULT true,
    "order_no" DECIMAL NOT NULL DEFAULT 0,
    "is_grid_column" BOOLEAN NOT NULL DEFAULT true,
    "is_searchable" BOOLEAN NOT NULL DEFAULT true,
    "is_sortable" BOOLEAN NOT NULL DEFAULT true,
    "field_type_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TEXT NOT NULL DEFAULT (datetime('now')),
    CONSTRAINT "master_entity_line_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    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,
    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
);

-- CreateTable
CREATE TABLE "permissions" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "name" TEXT NOT NULL,
    "slug" TEXT NOT NULL,
    "entity_id" INTEGER,
    "order_no" DECIMAL NOT NULL DEFAULT 0,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TEXT NOT NULL DEFAULT (datetime('now')),
    CONSTRAINT "permissions_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    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
);

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

    PRIMARY KEY ("company_id", "role_id", "permission_id"),
    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,
    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
);

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

    PRIMARY KEY ("company_id", "user_id", "permission_id"),
    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,
    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
);

-- CreateTable
CREATE TABLE "menu" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "slug" TEXT,
    "description" TEXT,
    "menu_type" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER NOT NULL,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TEXT NOT NULL DEFAULT (datetime('now')),
    "updated_at" DATETIME,
    "deleted_at" DATETIME,
    CONSTRAINT "menu_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "menu_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users" ("company_id", "id") ON DELETE RESTRICT ON UPDATE CASCADE,
    CONSTRAINT "menu_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users" ("company_id", "id") ON DELETE RESTRICT ON UPDATE CASCADE,
    CONSTRAINT "menu_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users" ("company_id", "id") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "menu_types" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "name" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TEXT NOT NULL DEFAULT (datetime('now')),
    CONSTRAINT "menu_types_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "menu_items" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "menu_id" INTEGER NOT NULL,
    "name" TEXT NOT NULL,
    "target" TEXT,
    "parent_id" INTEGER,
    "permission_id" INTEGER,
    "entity_id" INTEGER,
    "link_type" INTEGER,
    "order_no" DECIMAL NOT NULL DEFAULT 0,
    "menu_img" TEXT,
    "short_cut_keys" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_by" INTEGER,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TEXT DEFAULT (datetime('now')),
    "updated_at" DATETIME,
    "deleted_at" DATETIME,
    CONSTRAINT "menu_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    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,
    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,
    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
);

-- CreateTable
CREATE TABLE "email_templates" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "slug" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "subject" TEXT NOT NULL,
    "template_body" TEXT NOT NULL,
    "email_template_process_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_at" TEXT NOT NULL DEFAULT (datetime('now')),
    "created_by" INTEGER NOT NULL,
    "updated_at" DATETIME,
    "updated_by" INTEGER,
    "deleted_at" DATETIME,
    "deleted_by" INTEGER,
    "company_id" INTEGER NOT NULL,
    CONSTRAINT "email_templates_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "email_templates_email_template_process_id_company_id_fkey" FOREIGN KEY ("email_template_process_id", "company_id") REFERENCES "email_template_process" ("id", "company_id") ON DELETE RESTRICT ON UPDATE CASCADE,
    CONSTRAINT "email_templates_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "email_templates_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "email_templates_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "email_template_tags" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "slug" TEXT NOT NULL,
    "name" TEXT,
    "description" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    CONSTRAINT "email_template_tags_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "email_template_process" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "slug" TEXT NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    CONSTRAINT "email_template_process_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "email_template_process_tags_mapping" (
    "transfer_status" INTEGER DEFAULT 1,
    "email_template_process_id" INTEGER NOT NULL,
    "email_template_tag_id" INTEGER NOT NULL,
    "company_id" INTEGER NOT NULL,

    PRIMARY KEY ("email_template_process_id", "email_template_tag_id", "company_id"),
    CONSTRAINT "email_template_process_tags_mapping_email_template_process_id_company_id_fkey" FOREIGN KEY ("email_template_process_id", "company_id") REFERENCES "email_template_process" ("id", "company_id") ON DELETE RESTRICT ON UPDATE CASCADE,
    CONSTRAINT "email_template_process_tags_mapping_email_template_tag_id_company_id_fkey" FOREIGN KEY ("email_template_tag_id", "company_id") REFERENCES "email_template_tags" ("id", "company_id") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "email_template_assignment" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "email_template_process_id" INTEGER NOT NULL,
    "template_id" INTEGER NOT NULL,
    "recipient_type" TEXT NOT NULL DEFAULT 'tag',
    "email_to" TEXT,
    "company_id" INTEGER NOT NULL,
    "created_at" TEXT NOT NULL DEFAULT (datetime('now')),
    "created_by" INTEGER NOT NULL,
    CONSTRAINT "email_template_assignment_email_template_process_id_company_id_fkey" FOREIGN KEY ("email_template_process_id", "company_id") REFERENCES "email_template_process" ("id", "company_id") ON DELETE RESTRICT ON UPDATE CASCADE,
    CONSTRAINT "email_template_assignment_template_id_company_id_fkey" FOREIGN KEY ("template_id", "company_id") REFERENCES "email_templates" ("id", "company_id") ON DELETE RESTRICT ON UPDATE CASCADE,
    CONSTRAINT "email_template_assignment_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "email_template_recipient_tags" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "slug" TEXT NOT NULL,
    "name" TEXT,
    "description" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    CONSTRAINT "email_template_recipient_tags_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "app_category_types" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "category_type_id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "company_id" INTEGER NOT NULL,
    "created_at" TEXT NOT NULL DEFAULT (datetime('now')),
    "created_by" INTEGER NOT NULL,
    "updated_at" DATETIME,
    "updated_by" INTEGER,
    "deleted_at" DATETIME,
    "deleted_by" INTEGER,
    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,
    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,
    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
);

-- CreateTable
CREATE TABLE "app_categories" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "category_type_id" TEXT NOT NULL,
    "category_id" TEXT NOT NULL,
    "parent_id" TEXT,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "company_id" INTEGER NOT NULL,
    "created_at" TEXT NOT NULL DEFAULT (datetime('now')),
    "created_by" INTEGER NOT NULL,
    "updated_at" DATETIME,
    "updated_by" INTEGER,
    "deleted_at" DATETIME,
    "deleted_by" INTEGER,
    CONSTRAINT "app_categories_parent_id_fkey" FOREIGN KEY ("parent_id") REFERENCES "app_categories" ("category_id") ON DELETE SET NULL ON UPDATE CASCADE,
    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,
    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,
    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,
    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
);

-- CreateTable
CREATE TABLE "app_configurations" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "order_no" DECIMAL NOT NULL DEFAULT 0,
    "config_key" TEXT NOT NULL,
    "category_id" TEXT NOT NULL,
    "config_value" TEXT,
    "config_file_value" TEXT,
    "config_value_type" TEXT NOT NULL,
    "config_field_type" TEXT NOT NULL,
    "display_config" BOOLEAN NOT NULL DEFAULT true,
    "company_id" INTEGER NOT NULL,
    "created_at" TEXT NOT NULL DEFAULT (datetime('now')),
    "created_by" INTEGER NOT NULL,
    "updated_at" DATETIME,
    "updated_by" INTEGER,
    "deleted_at" DATETIME,
    "deleted_by" INTEGER,
    CONSTRAINT "app_configurations_category_id_company_id_fkey" FOREIGN KEY ("category_id", "company_id") REFERENCES "app_categories" ("category_id", "company_id") ON DELETE RESTRICT ON UPDATE CASCADE,
    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,
    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,
    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
);

-- CreateTable
CREATE TABLE "designations" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "code" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TEXT NOT NULL DEFAULT (datetime('now')),
    "created_by" INTEGER NOT NULL,
    "updated_at" DATETIME,
    "updated_by" INTEGER,
    "deleted_at" DATETIME,
    "deleted_by" INTEGER,
    CONSTRAINT "designations_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "designations_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "designations_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "designations_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "departments" (
    "transfer_status" INTEGER DEFAULT 1,
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "code" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "department_head_id" INTEGER,
    "company_id" INTEGER NOT NULL,
    "created_at" TEXT NOT NULL DEFAULT (datetime('now')),
    "created_by" INTEGER NOT NULL,
    "updated_at" DATETIME,
    "updated_by" INTEGER,
    "deleted_at" DATETIME,
    "deleted_by" INTEGER,
    CONSTRAINT "departments_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    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,
    CONSTRAINT "departments_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "departments_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "departments_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "file_upload_logs" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "doc_name" TEXT,
    "org_name" TEXT,
    "extension" TEXT,
    "description" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    CONSTRAINT "file_upload_logs_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "company_details" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "code" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "logo" TEXT,
    "registration_number" TEXT NOT NULL,
    "tax_idenitification_number" TEXT NOT NULL,
    "address" TEXT NOT NULL,
    "phone" TEXT NOT NULL,
    "fax" TEXT,
    "email" TEXT NOT NULL,
    "website" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" DATETIME,
    CONSTRAINT "company_details_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "company_details_created_by_fkey" FOREIGN KEY ("created_by") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "company_details_updated_by_fkey" FOREIGN KEY ("updated_by") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "company_details_deleted_by_fkey" FOREIGN KEY ("deleted_by") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "warehouses" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "company_id" INTEGER NOT NULL,
    "code" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" DATETIME,
    CONSTRAINT "warehouses_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "warehouses_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "warehouses_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "warehouses_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "bins" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "company_id" INTEGER NOT NULL,
    "warehouse_id" INTEGER NOT NULL,
    "code" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" DATETIME,
    CONSTRAINT "bins_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "bins_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "bins_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "bins_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "bins_company_id_warehouse_id_fkey" FOREIGN KEY ("company_id", "warehouse_id") REFERENCES "warehouses" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "units_of_measure" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "company_id" INTEGER NOT NULL,
    "code" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" DATETIME,
    CONSTRAINT "units_of_measure_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "units_of_measure_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "units_of_measure_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "units_of_measure_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "item_statuses" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "company_id" INTEGER NOT NULL,
    "code" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" DATETIME,
    CONSTRAINT "item_statuses_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "item_statuses_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "item_statuses_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "item_statuses_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "item_groups" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "company_id" INTEGER NOT NULL,
    "parent_id" INTEGER,
    "code" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" DATETIME,
    CONSTRAINT "item_groups_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "item_groups_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "item_groups_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "item_groups_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "item_types" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "company_id" INTEGER NOT NULL,
    "parent_id" INTEGER,
    "code" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" DATETIME,
    CONSTRAINT "item_types_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "item_types_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "item_types_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "item_types_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "item_categories" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "company_id" INTEGER NOT NULL,
    "parent_category_id" INTEGER,
    "code" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" DATETIME,
    CONSTRAINT "item_categories_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "item_categories_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "item_categories_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "item_categories_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "organizations" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "company_id" INTEGER NOT NULL,
    "parent_id" INTEGER,
    "code" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" DATETIME,
    CONSTRAINT "organizations_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "organizations_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "organizations_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "organizations_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "items" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "company_id" INTEGER NOT NULL,
    "parent_id" INTEGER,
    "code" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "part_number" TEXT,
    "item_group_id" INTEGER,
    "item_category_id" INTEGER NOT NULL,
    "organization_id" INTEGER NOT NULL,
    "item_status_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" DATETIME,
    CONSTRAINT "items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "items_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "items_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "items_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "items_company_id_item_group_id_fkey" FOREIGN KEY ("company_id", "item_group_id") REFERENCES "item_groups" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "items_company_id_item_category_id_fkey" FOREIGN KEY ("company_id", "item_category_id") REFERENCES "item_categories" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "items_company_id_organization_id_fkey" FOREIGN KEY ("company_id", "organization_id") REFERENCES "organizations" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "items_company_id_item_status_id_fkey" FOREIGN KEY ("company_id", "item_status_id") REFERENCES "item_statuses" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "item_uom" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "company_id" INTEGER NOT NULL,
    "item_id" INTEGER NOT NULL,
    "uom_id" INTEGER NOT NULL,
    "is_base_uom" INTEGER NOT NULL DEFAULT 1,
    "conversion_factor" TEXT NOT NULL,
    "item_cost" DECIMAL NOT NULL DEFAULT 0,
    "barcode" TEXT NOT NULL,
    "description" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" DATETIME,
    CONSTRAINT "item_uom_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "item_uom_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "item_uom_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "item_uom_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "item_uom_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "item_uom_company_id_uom_id_fkey" FOREIGN KEY ("company_id", "uom_id") REFERENCES "units_of_measure" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "stock_take_statuses" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "company_id" INTEGER NOT NULL,
    "code" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" DATETIME,
    CONSTRAINT "stock_take_statuses_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "stock_take_statuses_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "stock_take_statuses_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "stock_take_statuses_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "stock_take" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "company_id" INTEGER NOT NULL,
    "organization_id" INTEGER NOT NULL,
    "warehouse_id" INTEGER NOT NULL,
    "transaction_number" TEXT NOT NULL,
    "name" TEXT,
    "start_date" DATETIME NOT NULL,
    "end_date" DATETIME NOT NULL,
    "stock_take_status_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" DATETIME,
    CONSTRAINT "stock_take_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "stock_take_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "stock_take_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "stock_take_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "stock_take_company_id_organization_id_fkey" FOREIGN KEY ("company_id", "organization_id") REFERENCES "organizations" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "stock_take_company_id_warehouse_id_fkey" FOREIGN KEY ("company_id", "warehouse_id") REFERENCES "warehouses" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "stock_take_company_id_stock_take_status_id_fkey" FOREIGN KEY ("company_id", "stock_take_status_id") REFERENCES "stock_take_statuses" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "stock_take_user_mapping" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "company_id" INTEGER NOT NULL,
    "stock_take_id" INTEGER NOT NULL,
    "user_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" DATETIME,
    CONSTRAINT "stock_take_user_mapping_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "stock_take_user_mapping_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "stock_take_user_mapping_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "stock_take_user_mapping_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "stock_take_user_mapping_company_id_stock_take_id_fkey" FOREIGN KEY ("company_id", "stock_take_id") REFERENCES "stock_take" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "stock_take_user_mapping_company_id_user_id_fkey" FOREIGN KEY ("company_id", "user_id") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "onhand_stocks" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "company_id" INTEGER NOT NULL,
    "stock_take_id" INTEGER NOT NULL,
    "organization_id" INTEGER NOT NULL,
    "lot_number" TEXT,
    "line_no" INTEGER NOT NULL,
    "warehouse_id" INTEGER NOT NULL,
    "bin_id" INTEGER NOT NULL,
    "item_id" INTEGER NOT NULL,
    "uom_id" INTEGER NOT NULL,
    "onhand_quantity" INTEGER NOT NULL,
    "item_status_id" INTEGER NOT NULL,
    "identified_quantity" INTEGER NOT NULL,
    "version_number" INTEGER NOT NULL,
    "is_audit_completed" BOOLEAN NOT NULL DEFAULT false,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" DATETIME,
    CONSTRAINT "onhand_stocks_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "onhand_stocks_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "onhand_stocks_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "onhand_stocks_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "onhand_stocks_company_id_stock_take_id_fkey" FOREIGN KEY ("company_id", "stock_take_id") REFERENCES "stock_take" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "onhand_stocks_company_id_organization_id_fkey" FOREIGN KEY ("company_id", "organization_id") REFERENCES "organizations" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "onhand_stocks_company_id_warehouse_id_fkey" FOREIGN KEY ("company_id", "warehouse_id") REFERENCES "warehouses" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "onhand_stocks_company_id_bin_id_fkey" FOREIGN KEY ("company_id", "bin_id") REFERENCES "bins" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "onhand_stocks_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "onhand_stocks_company_id_uom_id_fkey" FOREIGN KEY ("company_id", "uom_id") REFERENCES "units_of_measure" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "onhand_stocks_company_id_item_status_id_fkey" FOREIGN KEY ("company_id", "item_status_id") REFERENCES "item_statuses" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "stock_audit_entry_header" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "company_id" INTEGER NOT NULL,
    "stock_take_id" INTEGER NOT NULL,
    "version_number" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" DATETIME,
    CONSTRAINT "stock_audit_entry_header_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "stock_audit_entry_header_company_id_created_by_fkey" FOREIGN KEY ("company_id", "created_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "stock_audit_entry_header_company_id_updated_by_fkey" FOREIGN KEY ("company_id", "updated_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "stock_audit_entry_header_company_id_deleted_by_fkey" FOREIGN KEY ("company_id", "deleted_by") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "stock_audit_entry_header_company_id_stock_take_id_fkey" FOREIGN KEY ("company_id", "stock_take_id") REFERENCES "stock_take" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "stock_audit_entry_line_items" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "company_id" INTEGER NOT NULL,
    "stock_audit_entry_id" INTEGER NOT NULL,
    "stock_take_id" INTEGER NOT NULL,
    "user_id" INTEGER NOT NULL,
    "warehouse_id" INTEGER NOT NULL,
    "bin_id" INTEGER NOT NULL,
    "item_id" INTEGER NOT NULL,
    "uom_id" INTEGER NOT NULL,
    "quantity" INTEGER NOT NULL,
    "item_status_id" INTEGER NOT NULL,
    "lot_number" TEXT,
    CONSTRAINT "stock_audit_entry_line_items_company_id_stock_audit_entry_id_fkey" FOREIGN KEY ("company_id", "stock_audit_entry_id") REFERENCES "stock_audit_entry_header" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "stock_audit_entry_line_items_company_id_stock_take_id_fkey" FOREIGN KEY ("company_id", "stock_take_id") REFERENCES "stock_take" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "stock_audit_entry_line_items_company_id_user_id_fkey" FOREIGN KEY ("company_id", "user_id") REFERENCES "users" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "stock_audit_entry_line_items_company_id_warehouse_id_fkey" FOREIGN KEY ("company_id", "warehouse_id") REFERENCES "warehouses" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "stock_audit_entry_line_items_company_id_bin_id_fkey" FOREIGN KEY ("company_id", "bin_id") REFERENCES "bins" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "stock_audit_entry_line_items_company_id_item_id_fkey" FOREIGN KEY ("company_id", "item_id") REFERENCES "items" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "stock_audit_entry_line_items_company_id_uom_id_fkey" FOREIGN KEY ("company_id", "uom_id") REFERENCES "units_of_measure" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "stock_audit_entry_line_items_company_id_item_status_id_fkey" FOREIGN KEY ("company_id", "item_status_id") REFERENCES "item_statuses" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "device_registration" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "uuid" TEXT NOT NULL,
    "company_id" INTEGER NOT NULL,
    "device_name" TEXT NOT NULL,
    "device_unique_id" TEXT NOT NULL,
    "user_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER NOT NULL,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME NOT NULL,
    "deleted_by" INTEGER,
    "deleted_at" DATETIME,
    CONSTRAINT "device_registration_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    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,
    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,
    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,
    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
);

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

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

-- 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 "field_types_company_id_id_key" ON "field_types"("company_id", "id");

-- CreateIndex
CREATE INDEX "otps_company_id_user_id_purpose_idx" ON "otps"("company_id", "user_id", "purpose");

-- 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 "webservice_logs_company_id_id_key" ON "webservice_logs"("company_id", "id");

-- 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 "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 "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 "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 "master_entities_name_key" ON "master_entities"("name");

-- 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_name_display_name_key" ON "master_entity_line_items"("company_id", "master_grid_id", "field_name", "display_name");

-- 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 "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_types_company_id_id_key" ON "menu_types"("company_id", "id");

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

-- CreateIndex
CREATE UNIQUE INDEX "email_templates_company_id_id_key" ON "email_templates"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "email_templates_company_id_slug_key" ON "email_templates"("company_id", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "email_template_tags_company_id_id_key" ON "email_template_tags"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "email_template_tags_company_id_slug_key" ON "email_template_tags"("company_id", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "email_template_process_company_id_id_key" ON "email_template_process"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "email_template_process_company_id_slug_key" ON "email_template_process"("company_id", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "email_template_recipient_tags_company_id_id_key" ON "email_template_recipient_tags"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "email_template_recipient_tags_company_id_slug_key" ON "email_template_recipient_tags"("company_id", "slug");

-- 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_category_id_key" ON "app_categories"("category_id");

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

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

-- CreateIndex
CREATE UNIQUE INDEX "app_categories_company_id_name_key" ON "app_categories"("company_id", "name");

-- 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 "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 "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 "file_upload_logs_company_id_id_key" ON "file_upload_logs"("company_id", "id");

-- CreateIndex
CREATE INDEX "company_details_id_idx" ON "company_details"("id");

-- CreateIndex
CREATE UNIQUE INDEX "company_details_id_key" ON "company_details"("id");

-- CreateIndex
CREATE UNIQUE INDEX "company_details_uuid_key" ON "company_details"("uuid");

-- CreateIndex
CREATE UNIQUE INDEX "warehouses_company_id_id_key" ON "warehouses"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "warehouses_company_id_uuid_key" ON "warehouses"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "bins_company_id_id_key" ON "bins"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "bins_company_id_uuid_key" ON "bins"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "units_of_measure_company_id_id_key" ON "units_of_measure"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "units_of_measure_company_id_uuid_key" ON "units_of_measure"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "item_statuses_company_id_id_key" ON "item_statuses"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "item_statuses_company_id_uuid_key" ON "item_statuses"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "item_groups_company_id_id_key" ON "item_groups"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "item_groups_company_id_uuid_key" ON "item_groups"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "item_types_company_id_id_key" ON "item_types"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "item_types_company_id_uuid_key" ON "item_types"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "item_categories_company_id_id_key" ON "item_categories"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "item_categories_company_id_uuid_key" ON "item_categories"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "organizations_company_id_id_key" ON "organizations"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "organizations_company_id_uuid_key" ON "organizations"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "items_company_id_id_key" ON "items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "items_company_id_uuid_key" ON "items"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "item_uom_company_id_id_key" ON "item_uom"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "item_uom_company_id_uuid_key" ON "item_uom"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "stock_take_statuses_company_id_id_key" ON "stock_take_statuses"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "stock_take_statuses_company_id_uuid_key" ON "stock_take_statuses"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "stock_take_company_id_id_key" ON "stock_take"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "stock_take_company_id_uuid_key" ON "stock_take"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "stock_take_user_mapping_company_id_id_key" ON "stock_take_user_mapping"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "stock_take_user_mapping_company_id_uuid_key" ON "stock_take_user_mapping"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "onhand_stocks_company_id_id_key" ON "onhand_stocks"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "onhand_stocks_company_id_uuid_key" ON "onhand_stocks"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "stock_audit_entry_header_company_id_id_key" ON "stock_audit_entry_header"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "stock_audit_entry_header_company_id_uuid_key" ON "stock_audit_entry_header"("company_id", "uuid");

-- CreateIndex
CREATE UNIQUE INDEX "stock_audit_entry_header_company_id_version_number_key" ON "stock_audit_entry_header"("company_id", "version_number");

-- CreateIndex
CREATE UNIQUE INDEX "stock_audit_entry_line_items_company_id_id_key" ON "stock_audit_entry_line_items"("company_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "stock_audit_entry_line_items_company_id_uuid_key" ON "stock_audit_entry_line_items"("company_id", "uuid");

-- 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");
