-- RedefineTables
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_menu_types" (
    "id" INTEGER NOT NULL,
    "name" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TEXT NOT NULL DEFAULT (datetime('now')),
    "transfer_status" INTEGER DEFAULT 1,
    CONSTRAINT "menu_types_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_menu_types" ("company_id", "created_at", "id", "name", "status_id", "transfer_status") SELECT "company_id", "created_at", "id", "name", "status_id", "transfer_status" FROM "menu_types";
DROP TABLE "menu_types";
ALTER TABLE "new_menu_types" RENAME TO "menu_types";
CREATE UNIQUE INDEX "menu_types_company_id_id_key" ON "menu_types"("company_id", "id");
CREATE TABLE "new_item_types" (
    "id" INTEGER NOT NULL,
    "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,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME,
    "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
);
INSERT INTO "new_item_types" ("code", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "id", "name", "parent_id", "status_id", "updated_at", "updated_by", "uuid") SELECT "code", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "id", "name", "parent_id", "status_id", "updated_at", "updated_by", "uuid" FROM "item_types";
DROP TABLE "item_types";
ALTER TABLE "new_item_types" RENAME TO "item_types";
CREATE UNIQUE INDEX "item_types_company_id_id_key" ON "item_types"("company_id", "id");
CREATE UNIQUE INDEX "item_types_company_id_uuid_key" ON "item_types"("company_id", "uuid");
CREATE TABLE "new_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,
    "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
);
INSERT INTO "new_company_details" ("address", "code", "created_at", "created_by", "deleted_at", "deleted_by", "email", "fax", "id", "logo", "name", "phone", "registration_number", "status_id", "tax_idenitification_number", "updated_at", "updated_by", "uuid", "website") SELECT "address", "code", "created_at", "created_by", "deleted_at", "deleted_by", "email", "fax", "id", "logo", "name", "phone", "registration_number", "status_id", "tax_idenitification_number", "updated_at", "updated_by", "uuid", "website" FROM "company_details";
DROP TABLE "company_details";
ALTER TABLE "new_company_details" RENAME TO "company_details";
CREATE INDEX "company_details_id_idx" ON "company_details"("id");
CREATE UNIQUE INDEX "company_details_id_key" ON "company_details"("id");
CREATE UNIQUE INDEX "company_details_uuid_key" ON "company_details"("uuid");
CREATE TABLE "new_warehouses" (
    "id" INTEGER NOT NULL,
    "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,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME,
    "deleted_by" INTEGER,
    "deleted_at" DATETIME,
    CONSTRAINT "warehouses_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_warehouses" ("code", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "id", "name", "status_id", "updated_at", "updated_by", "uuid") SELECT "code", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "id", "name", "status_id", "updated_at", "updated_by", "uuid" FROM "warehouses";
DROP TABLE "warehouses";
ALTER TABLE "new_warehouses" RENAME TO "warehouses";
CREATE UNIQUE INDEX "warehouses_company_id_id_key" ON "warehouses"("company_id", "id");
CREATE UNIQUE INDEX "warehouses_company_id_uuid_key" ON "warehouses"("company_id", "uuid");
CREATE TABLE "new_organizations" (
    "id" INTEGER NOT NULL,
    "uuid" TEXT NOT NULL,
    "company_id" INTEGER NOT NULL,
    "code" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME,
    "deleted_by" INTEGER,
    "deleted_at" DATETIME,
    CONSTRAINT "organizations_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_organizations" ("code", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "description", "id", "name", "status_id", "updated_at", "updated_by", "uuid") SELECT "code", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "description", "id", "name", "status_id", "updated_at", "updated_by", "uuid" FROM "organizations";
DROP TABLE "organizations";
ALTER TABLE "new_organizations" RENAME TO "organizations";
CREATE UNIQUE INDEX "organizations_company_id_id_key" ON "organizations"("company_id", "id");
CREATE UNIQUE INDEX "organizations_company_id_uuid_key" ON "organizations"("company_id", "uuid");
CREATE TABLE "new_menu" (
    "id" INTEGER NOT NULL,
    "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,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TEXT NOT NULL DEFAULT (datetime('now')),
    "updated_at" DATETIME,
    "deleted_at" DATETIME,
    "transfer_status" INTEGER DEFAULT 1,
    CONSTRAINT "menu_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_menu" ("company_id", "created_at", "created_by", "deleted_at", "deleted_by", "description", "id", "menu_type", "name", "slug", "status_id", "transfer_status", "updated_at", "updated_by", "uuid") SELECT "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "description", "id", "menu_type", "name", "slug", "status_id", "transfer_status", "updated_at", "updated_by", "uuid" FROM "menu";
DROP TABLE "menu";
ALTER TABLE "new_menu" RENAME TO "menu";
CREATE UNIQUE INDEX "menu_company_id_id_key" ON "menu"("company_id", "id");
CREATE UNIQUE INDEX "menu_company_id_uuid_key" ON "menu"("company_id", "uuid");
CREATE TABLE "new_stock_audit_entry_header" (
    "id" INTEGER NOT NULL,
    "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,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME,
    "deleted_by" INTEGER,
    "deleted_at" DATETIME,
    "transfer_status" INTEGER DEFAULT 1,
    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_stock_take_id_fkey" FOREIGN KEY ("company_id", "stock_take_id") REFERENCES "stock_take" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_stock_audit_entry_header" ("company_id", "created_at", "created_by", "deleted_at", "deleted_by", "id", "status_id", "stock_take_id", "transfer_status", "updated_at", "updated_by", "uuid", "version_number") SELECT "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "id", "status_id", "stock_take_id", "transfer_status", "updated_at", "updated_by", "uuid", "version_number" FROM "stock_audit_entry_header";
DROP TABLE "stock_audit_entry_header";
ALTER TABLE "new_stock_audit_entry_header" RENAME TO "stock_audit_entry_header";
CREATE UNIQUE INDEX "stock_audit_entry_header_company_id_id_key" ON "stock_audit_entry_header"("company_id", "id");
CREATE UNIQUE INDEX "stock_audit_entry_header_company_id_uuid_key" ON "stock_audit_entry_header"("company_id", "uuid");
CREATE TABLE "new_items" (
    "id" INTEGER NOT NULL,
    "uuid" TEXT NOT NULL,
    "company_id" INTEGER NOT NULL,
    "code" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "part_number" TEXT,
    "item_group_id" INTEGER,
    "item_type_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,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME,
    "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_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
);
INSERT INTO "new_items" ("code", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "description", "id", "item_category_id", "item_group_id", "item_status_id", "item_type_id", "name", "organization_id", "part_number", "status_id", "updated_at", "updated_by", "uuid") SELECT "code", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "description", "id", "item_category_id", "item_group_id", "item_status_id", "item_type_id", "name", "organization_id", "part_number", "status_id", "updated_at", "updated_by", "uuid" FROM "items";
DROP TABLE "items";
ALTER TABLE "new_items" RENAME TO "items";
CREATE UNIQUE INDEX "items_company_id_organization_id_code_key" ON "items"("company_id", "organization_id", "code");
CREATE UNIQUE INDEX "items_company_id_id_key" ON "items"("company_id", "id");
CREATE UNIQUE INDEX "items_company_id_uuid_key" ON "items"("company_id", "uuid");
CREATE TABLE "new_item_categories" (
    "id" INTEGER NOT NULL,
    "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,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME,
    "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
);
INSERT INTO "new_item_categories" ("code", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "description", "id", "name", "parent_category_id", "status_id", "updated_at", "updated_by", "uuid") SELECT "code", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "description", "id", "name", "parent_category_id", "status_id", "updated_at", "updated_by", "uuid" FROM "item_categories";
DROP TABLE "item_categories";
ALTER TABLE "new_item_categories" RENAME TO "item_categories";
CREATE UNIQUE INDEX "item_categories_company_id_id_key" ON "item_categories"("company_id", "id");
CREATE UNIQUE INDEX "item_categories_company_id_uuid_key" ON "item_categories"("company_id", "uuid");
CREATE TABLE "new_item_statuses" (
    "id" INTEGER NOT NULL,
    "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,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME,
    "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
);
INSERT INTO "new_item_statuses" ("code", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "id", "name", "status_id", "updated_at", "updated_by", "uuid") SELECT "code", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "id", "name", "status_id", "updated_at", "updated_by", "uuid" FROM "item_statuses";
DROP TABLE "item_statuses";
ALTER TABLE "new_item_statuses" RENAME TO "item_statuses";
CREATE UNIQUE INDEX "item_statuses_company_id_id_key" ON "item_statuses"("company_id", "id");
CREATE UNIQUE INDEX "item_statuses_company_id_uuid_key" ON "item_statuses"("company_id", "uuid");
CREATE TABLE "new_roles" (
    "id" INTEGER NOT NULL,
    "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,
    "transfer_status" INTEGER DEFAULT 1,
    CONSTRAINT "roles_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_roles" ("company_id", "created_at", "created_by", "deleted_at", "deleted_by", "description", "id", "name", "status_id", "transfer_status", "updated_at", "updated_by", "uuid") SELECT "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "description", "id", "name", "status_id", "transfer_status", "updated_at", "updated_by", "uuid" FROM "roles";
DROP TABLE "roles";
ALTER TABLE "new_roles" RENAME TO "roles";
CREATE UNIQUE INDEX "roles_company_id_id_key" ON "roles"("company_id", "id");
CREATE UNIQUE INDEX "roles_company_id_uuid_key" ON "roles"("company_id", "uuid");
CREATE TABLE "new_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" BOOLEAN NOT NULL DEFAULT true,
    "conversion_factor" DECIMAL 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,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME,
    "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_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
);
INSERT INTO "new_item_uom" ("barcode", "company_id", "conversion_factor", "created_at", "created_by", "deleted_at", "deleted_by", "description", "id", "is_base_uom", "item_cost", "item_id", "status_id", "uom_id", "updated_at", "updated_by", "uuid") SELECT "barcode", "company_id", "conversion_factor", "created_at", "created_by", "deleted_at", "deleted_by", "description", "id", "is_base_uom", "item_cost", "item_id", "status_id", "uom_id", "updated_at", "updated_by", "uuid" FROM "item_uom";
DROP TABLE "item_uom";
ALTER TABLE "new_item_uom" RENAME TO "item_uom";
CREATE UNIQUE INDEX "item_uom_company_id_id_key" ON "item_uom"("company_id", "id");
CREATE UNIQUE INDEX "item_uom_company_id_uuid_key" ON "item_uom"("company_id", "uuid");
CREATE TABLE "new_app_configurations" (
    "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,
    "updated_at" DATETIME,
    "updated_by" INTEGER,
    "deleted_at" DATETIME,
    "deleted_by" INTEGER,
    "transfer_status" INTEGER DEFAULT 1,
    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
);
INSERT INTO "new_app_configurations" ("category_id", "company_id", "config_field_type", "config_file_value", "config_key", "config_value", "config_value_type", "created_at", "created_by", "deleted_at", "deleted_by", "display_config", "id", "order_no", "transfer_status", "updated_at", "updated_by", "uuid") SELECT "category_id", "company_id", "config_field_type", "config_file_value", "config_key", "config_value", "config_value_type", "created_at", "created_by", "deleted_at", "deleted_by", "display_config", "id", "order_no", "transfer_status", "updated_at", "updated_by", "uuid" FROM "app_configurations";
DROP TABLE "app_configurations";
ALTER TABLE "new_app_configurations" RENAME TO "app_configurations";
CREATE UNIQUE INDEX "app_configurations_company_id_id_key" ON "app_configurations"("company_id", "id");
CREATE UNIQUE INDEX "app_configurations_company_id_config_key_key" ON "app_configurations"("company_id", "config_key");
CREATE TABLE "new_bins" (
    "id" INTEGER NOT NULL,
    "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,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME,
    "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_warehouse_id_fkey" FOREIGN KEY ("company_id", "warehouse_id") REFERENCES "warehouses" ("company_id", "id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_bins" ("code", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "id", "name", "status_id", "updated_at", "updated_by", "uuid", "warehouse_id") SELECT "code", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "id", "name", "status_id", "updated_at", "updated_by", "uuid", "warehouse_id" FROM "bins";
DROP TABLE "bins";
ALTER TABLE "new_bins" RENAME TO "bins";
CREATE UNIQUE INDEX "bins_company_id_id_key" ON "bins"("company_id", "id");
CREATE UNIQUE INDEX "bins_company_id_uuid_key" ON "bins"("company_id", "uuid");
CREATE TABLE "new_field_types" (
    "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')),
    "transfer_status" INTEGER DEFAULT 1,
    CONSTRAINT "field_types_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_field_types" ("company_id", "created_at", "field_type", "id", "status_id", "transfer_status") SELECT "company_id", "created_at", "field_type", "id", "status_id", "transfer_status" FROM "field_types";
DROP TABLE "field_types";
ALTER TABLE "new_field_types" RENAME TO "field_types";
CREATE UNIQUE INDEX "field_types_company_id_id_key" ON "field_types"("company_id", "id");
CREATE TABLE "new_departments" (
    "id" INTEGER NOT NULL,
    "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,
    "updated_at" DATETIME,
    "updated_by" INTEGER,
    "deleted_at" DATETIME,
    "deleted_by" INTEGER,
    "transfer_status" INTEGER DEFAULT 1,
    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
);
INSERT INTO "new_departments" ("code", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "department_head_id", "description", "id", "name", "status_id", "transfer_status", "updated_at", "updated_by", "uuid") SELECT "code", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "department_head_id", "description", "id", "name", "status_id", "transfer_status", "updated_at", "updated_by", "uuid" FROM "departments";
DROP TABLE "departments";
ALTER TABLE "new_departments" RENAME TO "departments";
CREATE UNIQUE INDEX "departments_company_id_id_key" ON "departments"("company_id", "id");
CREATE UNIQUE INDEX "departments_company_id_uuid_key" ON "departments"("company_id", "uuid");
CREATE TABLE "new_master_entity_line_items" (
    "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')),
    "transfer_status" INTEGER DEFAULT 1,
    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
);
INSERT INTO "new_master_entity_line_items" ("company_id", "created_at", "display_name", "field_name", "field_type_id", "format", "id", "is_default", "is_grid_column", "is_searchable", "is_sortable", "master_grid_id", "order_no", "status_id", "transfer_status", "width") SELECT "company_id", "created_at", "display_name", "field_name", "field_type_id", "format", "id", "is_default", "is_grid_column", "is_searchable", "is_sortable", "master_grid_id", "order_no", "status_id", "transfer_status", "width" FROM "master_entity_line_items";
DROP TABLE "master_entity_line_items";
ALTER TABLE "new_master_entity_line_items" RENAME TO "master_entity_line_items";
CREATE UNIQUE INDEX "master_entity_line_items_company_id_id_key" ON "master_entity_line_items"("company_id", "id");
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");
CREATE TABLE "new_units_of_measure" (
    "id" INTEGER NOT NULL,
    "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,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME,
    "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
);
INSERT INTO "new_units_of_measure" ("code", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "id", "name", "status_id", "updated_at", "updated_by", "uuid") SELECT "code", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "id", "name", "status_id", "updated_at", "updated_by", "uuid" FROM "units_of_measure";
DROP TABLE "units_of_measure";
ALTER TABLE "new_units_of_measure" RENAME TO "units_of_measure";
CREATE UNIQUE INDEX "units_of_measure_company_id_id_key" ON "units_of_measure"("company_id", "id");
CREATE UNIQUE INDEX "units_of_measure_company_id_uuid_key" ON "units_of_measure"("company_id", "uuid");
CREATE TABLE "new_app_category_types" (
    "id" INTEGER NOT NULL,
    "uuid" TEXT NOT NULL,
    "category_type_id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "transfer_status" INTEGER DEFAULT 1,
    "company_id" INTEGER NOT NULL,
    "created_at" TEXT NOT NULL DEFAULT (datetime('now')),
    "created_by" INTEGER,
    "updated_at" DATETIME,
    "updated_by" INTEGER,
    "deleted_at" DATETIME,
    "deleted_by" INTEGER
);
INSERT INTO "new_app_category_types" ("category_type_id", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "description", "id", "name", "transfer_status", "updated_at", "updated_by", "uuid") SELECT "category_type_id", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "description", "id", "name", "transfer_status", "updated_at", "updated_by", "uuid" FROM "app_category_types";
DROP TABLE "app_category_types";
ALTER TABLE "new_app_category_types" RENAME TO "app_category_types";
CREATE UNIQUE INDEX "app_category_types_company_id_category_type_id_key" ON "app_category_types"("company_id", "category_type_id");
CREATE UNIQUE INDEX "app_category_types_company_id_id_key" ON "app_category_types"("company_id", "id");
CREATE UNIQUE INDEX "app_category_types_company_id_name_key" ON "app_category_types"("company_id", "name");
CREATE TABLE "new_menu_items" (
    "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,
    "transfer_status" INTEGER DEFAULT 1,
    CONSTRAINT "menu_items_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_menu_items" ("company_id", "created_at", "created_by", "deleted_at", "deleted_by", "entity_id", "id", "link_type", "menu_id", "menu_img", "name", "order_no", "parent_id", "permission_id", "short_cut_keys", "status_id", "target", "transfer_status", "updated_at", "updated_by") SELECT "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "entity_id", "id", "link_type", "menu_id", "menu_img", "name", "order_no", "parent_id", "permission_id", "short_cut_keys", "status_id", "target", "transfer_status", "updated_at", "updated_by" FROM "menu_items";
DROP TABLE "menu_items";
ALTER TABLE "new_menu_items" RENAME TO "menu_items";
CREATE UNIQUE INDEX "menu_items_company_id_id_key" ON "menu_items"("company_id", "id");
CREATE TABLE "new_user_details" (
    "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,
    "updated_by" INTEGER,
    "deleted_by" INTEGER,
    "created_at" TEXT NOT NULL DEFAULT (datetime('now')),
    "updated_at" DATETIME,
    "deleted_at" DATETIME,
    "transfer_status" INTEGER DEFAULT 1,
    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
);
INSERT INTO "new_user_details" ("address", "code", "company_id", "country_code", "created_at", "created_by", "culture", "deleted_at", "deleted_by", "department_id", "designation_id", "dob", "first_name", "gender", "id", "last_name", "phone_number", "profile_pic", "transfer_status", "updated_at", "updated_by", "user_id", "user_time_zone") SELECT "address", "code", "company_id", "country_code", "created_at", "created_by", "culture", "deleted_at", "deleted_by", "department_id", "designation_id", "dob", "first_name", "gender", "id", "last_name", "phone_number", "profile_pic", "transfer_status", "updated_at", "updated_by", "user_id", "user_time_zone" FROM "user_details";
DROP TABLE "user_details";
ALTER TABLE "new_user_details" RENAME TO "user_details";
CREATE UNIQUE INDEX "user_details_company_id_user_id_key" ON "user_details"("company_id", "user_id");
CREATE TABLE "new_wizard_group" (
    "id" INTEGER NOT NULL,
    "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,
    "transfer_status" INTEGER DEFAULT 1
);
INSERT INTO "new_wizard_group" ("company_id", "created_at", "description", "id", "name", "slug", "status_id", "transfer_status", "uuid") SELECT "company_id", "created_at", "description", "id", "name", "slug", "status_id", "transfer_status", "uuid" FROM "wizard_group";
DROP TABLE "wizard_group";
ALTER TABLE "new_wizard_group" RENAME TO "wizard_group";
CREATE UNIQUE INDEX "wizard_group_company_id_id_key" ON "wizard_group"("company_id", "id");
CREATE UNIQUE INDEX "wizard_group_company_id_slug_key" ON "wizard_group"("company_id", "slug");
CREATE TABLE "new_master_entities" (
    "id" INTEGER NOT NULL,
    "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,
    "transfer_status" INTEGER DEFAULT 1,
    CONSTRAINT "master_entities_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_master_entities" ("add_query_information", "associated_tables", "company_id", "created_at", "dashboard_wizard_columns", "dashboard_wizard_group_id", "dashboard_wizard_options", "dashboard_wizard_order_no", "dashboard_wizard_rows", "dashboard_wizard_type", "deleted_at", "edit_query_information", "entity_name", "entity_type", "form_information", "id", "name", "preset_query_information", "primary_table", "query_information", "static_page_content", "status_id", "transfer_status", "uuid") SELECT "add_query_information", "associated_tables", "company_id", "created_at", "dashboard_wizard_columns", "dashboard_wizard_group_id", "dashboard_wizard_options", "dashboard_wizard_order_no", "dashboard_wizard_rows", "dashboard_wizard_type", "deleted_at", "edit_query_information", "entity_name", "entity_type", "form_information", "id", "name", "preset_query_information", "primary_table", "query_information", "static_page_content", "status_id", "transfer_status", "uuid" FROM "master_entities";
DROP TABLE "master_entities";
ALTER TABLE "new_master_entities" RENAME TO "master_entities";
CREATE UNIQUE INDEX "master_entities_name_key" ON "master_entities"("name");
CREATE UNIQUE INDEX "master_entities_company_id_id_key" ON "master_entities"("company_id", "id");
CREATE UNIQUE INDEX "master_entities_company_id_entity_name_key" ON "master_entities"("company_id", "entity_name");
CREATE TABLE "new_app_categories" (
    "id" INTEGER NOT NULL,
    "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 DEFAULT (datetime('now')),
    "created_by" INTEGER,
    "updated_at" DATETIME,
    "updated_by" INTEGER,
    "deleted_at" DATETIME,
    "deleted_by" INTEGER,
    "transfer_status" INTEGER DEFAULT 1,
    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
);
INSERT INTO "new_app_categories" ("category_id", "category_type_id", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "description", "id", "name", "parent_id", "transfer_status", "updated_at", "updated_by", "uuid") SELECT "category_id", "category_type_id", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "description", "id", "name", "parent_id", "transfer_status", "updated_at", "updated_by", "uuid" FROM "app_categories";
DROP TABLE "app_categories";
ALTER TABLE "new_app_categories" RENAME TO "app_categories";
CREATE UNIQUE INDEX "app_categories_category_id_key" ON "app_categories"("category_id");
CREATE UNIQUE INDEX "app_categories_company_id_category_id_key" ON "app_categories"("company_id", "category_id");
CREATE UNIQUE INDEX "app_categories_company_id_id_key" ON "app_categories"("company_id", "id");
CREATE UNIQUE INDEX "app_categories_company_id_name_key" ON "app_categories"("company_id", "name");
CREATE TABLE "new_permissions" (
    "id" INTEGER NOT NULL,
    "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')),
    "transfer_status" INTEGER DEFAULT 1,
    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
);
INSERT INTO "new_permissions" ("company_id", "created_at", "entity_id", "id", "name", "order_no", "slug", "status_id", "transfer_status") SELECT "company_id", "created_at", "entity_id", "id", "name", "order_no", "slug", "status_id", "transfer_status" FROM "permissions";
DROP TABLE "permissions";
ALTER TABLE "new_permissions" RENAME TO "permissions";
CREATE INDEX "permissions_company_id_order_no_idx" ON "permissions"("company_id", "order_no");
CREATE UNIQUE INDEX "permissions_company_id_slug_key" ON "permissions"("company_id", "slug");
CREATE UNIQUE INDEX "permissions_company_id_id_key" ON "permissions"("company_id", "id");
CREATE TABLE "new_designations" (
    "id" INTEGER NOT NULL,
    "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,
    "updated_at" DATETIME,
    "updated_by" INTEGER,
    "deleted_at" DATETIME,
    "deleted_by" INTEGER,
    "transfer_status" INTEGER DEFAULT 1,
    CONSTRAINT "designations_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_designations" ("code", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "description", "id", "name", "status_id", "transfer_status", "updated_at", "updated_by", "uuid") SELECT "code", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "description", "id", "name", "status_id", "transfer_status", "updated_at", "updated_by", "uuid" FROM "designations";
DROP TABLE "designations";
ALTER TABLE "new_designations" RENAME TO "designations";
CREATE UNIQUE INDEX "designations_company_id_id_key" ON "designations"("company_id", "id");
CREATE UNIQUE INDEX "designations_company_id_uuid_key" ON "designations"("company_id", "uuid");
CREATE TABLE "new_item_groups" (
    "id" INTEGER NOT NULL,
    "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,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME,
    "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
);
INSERT INTO "new_item_groups" ("code", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "id", "name", "parent_id", "status_id", "updated_at", "updated_by", "uuid") SELECT "code", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "id", "name", "parent_id", "status_id", "updated_at", "updated_by", "uuid" FROM "item_groups";
DROP TABLE "item_groups";
ALTER TABLE "new_item_groups" RENAME TO "item_groups";
CREATE UNIQUE INDEX "item_groups_company_id_id_key" ON "item_groups"("company_id", "id");
CREATE UNIQUE INDEX "item_groups_company_id_uuid_key" ON "item_groups"("company_id", "uuid");
CREATE TABLE "new_users" (
    "id" INTEGER NOT NULL,
    "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,
    "transfer_status" INTEGER DEFAULT 1,
    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
);
INSERT INTO "new_users" ("company_id", "created_at", "created_by", "deleted_at", "deleted_by", "email", "email_verified", "id", "last_login", "last_login_device", "password", "role", "status_id", "transfer_status", "updated_at", "updated_by", "username", "uuid") SELECT "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "email", "email_verified", "id", "last_login", "last_login_device", "password", "role", "status_id", "transfer_status", "updated_at", "updated_by", "username", "uuid" FROM "users";
DROP TABLE "users";
ALTER TABLE "new_users" RENAME TO "users";
CREATE UNIQUE INDEX "users_company_id_uuid_key" ON "users"("company_id", "uuid");
CREATE UNIQUE INDEX "users_company_id_email_role_key" ON "users"("company_id", "email", "role");
CREATE UNIQUE INDEX "users_company_id_username_key" ON "users"("company_id", "username");
CREATE UNIQUE INDEX "users_company_id_id_key" ON "users"("company_id", "id");
CREATE TABLE "new_stock_take_statuses" (
    "id" INTEGER NOT NULL,
    "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,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME,
    "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
);
INSERT INTO "new_stock_take_statuses" ("code", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "id", "name", "status_id", "updated_at", "updated_by", "uuid") SELECT "code", "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "id", "name", "status_id", "updated_at", "updated_by", "uuid" FROM "stock_take_statuses";
DROP TABLE "stock_take_statuses";
ALTER TABLE "new_stock_take_statuses" RENAME TO "stock_take_statuses";
CREATE UNIQUE INDEX "stock_take_statuses_company_id_id_key" ON "stock_take_statuses"("company_id", "id");
CREATE UNIQUE INDEX "stock_take_statuses_company_id_uuid_key" ON "stock_take_statuses"("company_id", "uuid");
CREATE TABLE "new_stock_take" (
    "id" INTEGER NOT NULL,
    "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 DEFAULT (datetime('now')),
    "end_date" DATETIME DEFAULT (datetime('now')),
    "stock_take_status_id" INTEGER NOT NULL,
    "status_id" INTEGER NOT NULL DEFAULT 1,
    "created_by" INTEGER,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME,
    "deleted_by" INTEGER,
    "deleted_at" DATETIME,
    "transfer_status" INTEGER DEFAULT 1,
    CONSTRAINT "stock_take_status_id_fkey" FOREIGN KEY ("status_id") REFERENCES "statuses" ("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
);
INSERT INTO "new_stock_take" ("company_id", "created_at", "created_by", "deleted_at", "deleted_by", "end_date", "id", "name", "organization_id", "start_date", "status_id", "stock_take_status_id", "transaction_number", "transfer_status", "updated_at", "updated_by", "uuid", "warehouse_id") SELECT "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "end_date", "id", "name", "organization_id", "start_date", "status_id", "stock_take_status_id", "transaction_number", "transfer_status", "updated_at", "updated_by", "uuid", "warehouse_id" FROM "stock_take";
DROP TABLE "stock_take";
ALTER TABLE "new_stock_take" RENAME TO "stock_take";
CREATE UNIQUE INDEX "stock_take_company_id_id_key" ON "stock_take"("company_id", "id");
CREATE UNIQUE INDEX "stock_take_company_id_uuid_key" ON "stock_take"("company_id", "uuid");
CREATE TABLE "new_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,
    "created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
    "updated_by" INTEGER,
    "updated_at" DATETIME,
    "deleted_by" INTEGER,
    "deleted_at" DATETIME,
    "transfer_status" INTEGER DEFAULT 1,
    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_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
);
INSERT INTO "new_stock_take_user_mapping" ("company_id", "created_at", "created_by", "deleted_at", "deleted_by", "id", "status_id", "stock_take_id", "transfer_status", "updated_at", "updated_by", "user_id", "uuid") SELECT "company_id", "created_at", "created_by", "deleted_at", "deleted_by", "id", "status_id", "stock_take_id", "transfer_status", "updated_at", "updated_by", "user_id", "uuid" FROM "stock_take_user_mapping";
DROP TABLE "stock_take_user_mapping";
ALTER TABLE "new_stock_take_user_mapping" RENAME TO "stock_take_user_mapping";
CREATE UNIQUE INDEX "stock_take_user_mapping_company_id_id_key" ON "stock_take_user_mapping"("company_id", "id");
CREATE UNIQUE INDEX "stock_take_user_mapping_company_id_uuid_key" ON "stock_take_user_mapping"("company_id", "uuid");
PRAGMA foreign_key_check("menu_types");
PRAGMA foreign_key_check("item_types");
PRAGMA foreign_key_check("company_details");
PRAGMA foreign_key_check("warehouses");
PRAGMA foreign_key_check("organizations");
PRAGMA foreign_key_check("menu");
PRAGMA foreign_key_check("stock_audit_entry_header");
PRAGMA foreign_key_check("items");
PRAGMA foreign_key_check("item_categories");
PRAGMA foreign_key_check("item_statuses");
PRAGMA foreign_key_check("roles");
PRAGMA foreign_key_check("item_uom");
PRAGMA foreign_key_check("app_configurations");
PRAGMA foreign_key_check("bins");
PRAGMA foreign_key_check("field_types");
PRAGMA foreign_key_check("departments");
PRAGMA foreign_key_check("master_entity_line_items");
PRAGMA foreign_key_check("units_of_measure");
PRAGMA foreign_key_check("app_category_types");
PRAGMA foreign_key_check("menu_items");
PRAGMA foreign_key_check("user_details");
PRAGMA foreign_key_check("wizard_group");
PRAGMA foreign_key_check("master_entities");
PRAGMA foreign_key_check("app_categories");
PRAGMA foreign_key_check("permissions");
PRAGMA foreign_key_check("designations");
PRAGMA foreign_key_check("item_groups");
PRAGMA foreign_key_check("users");
PRAGMA foreign_key_check("stock_take_statuses");
PRAGMA foreign_key_check("stock_take");
PRAGMA foreign_key_check("stock_take_user_mapping");
PRAGMA foreign_keys=ON;
