﻿CREATE TABLE "iot_Area" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_Area" PRIMARY KEY,
    "Type" INTEGER NOT NULL,
    "CustomType" TEXT NULL,
    "IsDeleted" TEXT NULL,
    "Name" TEXT NULL,
    "Number" TEXT NULL,
    "DisplayOrder" INTEGER NOT NULL,
    "Left" INTEGER NOT NULL,
    "Right" INTEGER NOT NULL,
    "ParentId" TEXT NULL,
    CONSTRAINT "FK_iot_Area_iot_Area_ParentId" FOREIGN KEY ("ParentId") REFERENCES "iot_Area" ("Id") ON DELETE RESTRICT
);


CREATE TABLE "iot_IoTProductCategory" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_IoTProductCategory" PRIMARY KEY,
    "Image" TEXT NULL,
    "IsDeleted" TEXT NULL,
    "Name" TEXT NULL,
    "Number" TEXT NULL,
    "DisplayOrder" INTEGER NOT NULL,
    "Left" INTEGER NOT NULL,
    "Right" INTEGER NOT NULL,
    "ParentId" TEXT NULL,
    CONSTRAINT "FK_iot_IoTProductCategory_iot_IoTProductCategory_ParentId" FOREIGN KEY ("ParentId") REFERENCES "iot_IoTProductCategory" ("Id") ON DELETE RESTRICT
);


CREATE TABLE "iot_LiveRecord" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_LiveRecord" PRIMARY KEY,
    "DeviceNumber" TEXT NOT NULL,
    "DeviceName" TEXT NULL,
    "Name" TEXT NULL,
    "Value" TEXT NULL,
    "IsDeleted" TEXT NULL
);


CREATE TABLE "iot_Setting" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_Setting" PRIMARY KEY,
    "Name" TEXT NOT NULL,
    "Value" TEXT NULL,
    "Type" INTEGER NOT NULL,
    "IsDeleted" TEXT NULL
);


CREATE TABLE "iot_Site" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_Site" PRIMARY KEY,
    "Name" TEXT NOT NULL,
    "Icon" TEXT NULL,
    "Description" TEXT NULL,
    "Key" TEXT NULL,
    "Home" TEXT NULL,
    "Login" TEXT NULL,
    "Logout" TEXT NULL,
    "Disabled" INTEGER NOT NULL,
    "DisplayOrder" INTEGER NOT NULL,
    "IsDeleted" TEXT NULL
);


CREATE TABLE "iot_User" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_User" PRIMARY KEY,
    "UserName" TEXT NOT NULL,
    "SecurityStamp" TEXT NULL,
    "PasswordHash" TEXT NULL,
    "PasswordConfirmed" INTEGER NOT NULL,
    "Email" TEXT NULL,
    "EmailConfirmed" INTEGER NOT NULL,
    "PhoneNumber" TEXT NULL,
    "PhoneNumberConfirmed" INTEGER NOT NULL,
    "RealName" TEXT NULL,
    "IdentityNumber" TEXT NULL,
    "IdentityConfirmed" INTEGER NOT NULL,
    "NickName" TEXT NULL,
    "Avatar" TEXT NULL,
    "Sex" INTEGER NULL,
    "Birthday" TEXT NULL,
    "LockoutEnabled" INTEGER NOT NULL,
    "AccessFailedCount" INTEGER NOT NULL,
    "LockoutEnd" TEXT NULL,
    "RowVersion" TEXT NULL,
    "IsDeleted" TEXT NULL
);


CREATE TABLE "iot_Organ" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_Organ" PRIMARY KEY,
    "Type" INTEGER NOT NULL,
    "CustomType" TEXT NULL,
    "Image" TEXT NULL,
    "Description" TEXT NULL,
    "AreaId" TEXT NULL,
    "IsReadOnly" INTEGER NOT NULL,
    "IsDeleted" TEXT NULL,
    "Name" TEXT NULL,
    "Number" TEXT NULL,
    "DisplayOrder" INTEGER NOT NULL,
    "Left" INTEGER NOT NULL,
    "Right" INTEGER NOT NULL,
    "ParentId" TEXT NULL,
    CONSTRAINT "FK_iot_Organ_iot_Area_AreaId" FOREIGN KEY ("AreaId") REFERENCES "iot_Area" ("Id") ON DELETE SET NULL,
    CONSTRAINT "FK_iot_Organ_iot_Organ_ParentId" FOREIGN KEY ("ParentId") REFERENCES "iot_Organ" ("Id") ON DELETE RESTRICT
);


CREATE TABLE "iot_IoTProduct" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_IoTProduct" PRIMARY KEY,
    "Name" TEXT NULL,
    "Number" TEXT NOT NULL,
    "Image" TEXT NULL,
    "Path" TEXT NULL,
    "ApiJson" TEXT NULL,
    "DisplayOrder" INTEGER NOT NULL,
    "IoTProductCategoryId" TEXT NULL,
    "IsDeleted" TEXT NULL,
    CONSTRAINT "FK_iot_IoTProduct_iot_IoTProductCategory_IoTProductCategoryId" FOREIGN KEY ("IoTProductCategoryId") REFERENCES "iot_IoTProductCategory" ("Id") ON DELETE SET NULL
);


CREATE TABLE "iot_Building" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_Building" PRIMARY KEY,
    "Type" INTEGER NOT NULL,
    "CustomType" TEXT NULL,
    "Image" TEXT NULL,
    "Description" TEXT NULL,
    "OrganId" TEXT NOT NULL,
    "AreaId" TEXT NULL,
    "IsDeleted" TEXT NULL,
    "Name" TEXT NULL,
    "Number" TEXT NULL,
    "DisplayOrder" INTEGER NOT NULL,
    "Left" INTEGER NOT NULL,
    "Right" INTEGER NOT NULL,
    "ParentId" TEXT NULL,
    CONSTRAINT "FK_iot_Building_iot_Area_AreaId" FOREIGN KEY ("AreaId") REFERENCES "iot_Area" ("Id") ON DELETE RESTRICT,
    CONSTRAINT "FK_iot_Building_iot_Building_ParentId" FOREIGN KEY ("ParentId") REFERENCES "iot_Building" ("Id") ON DELETE RESTRICT,
    CONSTRAINT "FK_iot_Building_iot_Organ_OrganId" FOREIGN KEY ("OrganId") REFERENCES "iot_Organ" ("Id") ON DELETE CASCADE
);


CREATE TABLE "iot_Department" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_Department" PRIMARY KEY,
    "Type" INTEGER NOT NULL,
    "CustomType" TEXT NULL,
    "OrganId" TEXT NOT NULL,
    "IsDeleted" TEXT NULL,
    "Name" TEXT NULL,
    "Number" TEXT NULL,
    "DisplayOrder" INTEGER NOT NULL,
    "Left" INTEGER NOT NULL,
    "Right" INTEGER NOT NULL,
    "ParentId" TEXT NULL,
    CONSTRAINT "FK_iot_Department_iot_Department_ParentId" FOREIGN KEY ("ParentId") REFERENCES "iot_Department" ("Id") ON DELETE RESTRICT,
    CONSTRAINT "FK_iot_Department_iot_Organ_OrganId" FOREIGN KEY ("OrganId") REFERENCES "iot_Organ" ("Id") ON DELETE CASCADE
);


CREATE TABLE "iot_OrganRole" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_OrganRole" PRIMARY KEY,
    "Name" TEXT NOT NULL,
    "Number" TEXT NOT NULL,
    "IsReadOnly" INTEGER NOT NULL,
    "OrganId" TEXT NOT NULL,
    "IsDeleted" TEXT NULL,
    CONSTRAINT "FK_iot_OrganRole_iot_Organ_OrganId" FOREIGN KEY ("OrganId") REFERENCES "iot_Organ" ("Id") ON DELETE CASCADE
);


CREATE TABLE "iot_OrganUser" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_OrganUser" PRIMARY KEY,
    "Type" INTEGER NOT NULL,
    "CustomType" TEXT NULL,
    "OrganId" TEXT NOT NULL,
    "UserId" TEXT NOT NULL,
    "IsDefault" INTEGER NOT NULL,
    "IsReadOnly" INTEGER NOT NULL,
    "IsDeleted" TEXT NULL,
    CONSTRAINT "FK_iot_OrganUser_iot_Organ_OrganId" FOREIGN KEY ("OrganId") REFERENCES "iot_Organ" ("Id") ON DELETE CASCADE,
    CONSTRAINT "FK_iot_OrganUser_iot_User_UserId" FOREIGN KEY ("UserId") REFERENCES "iot_User" ("Id") ON DELETE CASCADE
);


CREATE TABLE "iot_PermissionCategory" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_PermissionCategory" PRIMARY KEY,
    "OrganId" TEXT NULL,
    "IsDeleted" TEXT NULL,
    "Name" TEXT NULL,
    "Number" TEXT NULL,
    "DisplayOrder" INTEGER NOT NULL,
    "Left" INTEGER NOT NULL,
    "Right" INTEGER NOT NULL,
    "ParentId" TEXT NULL,
    CONSTRAINT "FK_iot_PermissionCategory_iot_Organ_OrganId" FOREIGN KEY ("OrganId") REFERENCES "iot_Organ" ("Id") ON DELETE RESTRICT,
    CONSTRAINT "FK_iot_PermissionCategory_iot_PermissionCategory_ParentId" FOREIGN KEY ("ParentId") REFERENCES "iot_PermissionCategory" ("Id") ON DELETE RESTRICT
);


CREATE TABLE "iot_Title" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_Title" PRIMARY KEY,
    "Name" TEXT NULL,
    "MinLevel" INTEGER NOT NULL,
    "MaxLevel" INTEGER NOT NULL,
    "OrganId" TEXT NOT NULL,
    "IsDeleted" TEXT NULL,
    CONSTRAINT "FK_iot_Title_iot_Organ_OrganId" FOREIGN KEY ("OrganId") REFERENCES "iot_Organ" ("Id") ON DELETE CASCADE
);


CREATE TABLE "iot_IoTApi" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_IoTApi" PRIMARY KEY,
    "Name" TEXT NULL,
    "Path" TEXT NULL,
    "Command" TEXT NULL,
    "Method" TEXT NULL,
    "IoTProductId" TEXT NOT NULL,
    "IsDeleted" TEXT NULL,
    CONSTRAINT "FK_iot_IoTApi_iot_IoTProduct_IoTProductId" FOREIGN KEY ("IoTProductId") REFERENCES "iot_IoTProduct" ("Id") ON DELETE CASCADE
);


CREATE TABLE "iot_IoTGateway" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_IoTGateway" PRIMARY KEY,
    "Name" TEXT NULL,
    "Number" TEXT NOT NULL,
    "IsOnline" INTEGER NOT NULL,
    "Image" TEXT NULL,
    "Version" TEXT NULL,
    "Password" TEXT NULL,
    "DisplayOrder" INTEGER NOT NULL,
    "Hidden" INTEGER NOT NULL,
    "BuildingId" TEXT NULL,
    "IsDeleted" TEXT NULL,
    CONSTRAINT "FK_iot_IoTGateway_iot_Building_BuildingId" FOREIGN KEY ("BuildingId") REFERENCES "iot_Building" ("Id") ON DELETE SET NULL
);


CREATE TABLE "iot_IoTScene" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_IoTScene" PRIMARY KEY,
    "Name" TEXT NOT NULL,
    "Image" TEXT NOT NULL,
    "Hidden" INTEGER NOT NULL,
    "DisplayOrder" INTEGER NOT NULL,
    "BuildingId" TEXT NOT NULL,
    "IsDeleted" TEXT NULL,
    CONSTRAINT "FK_iot_IoTScene_iot_Building_BuildingId" FOREIGN KEY ("BuildingId") REFERENCES "iot_Building" ("Id") ON DELETE CASCADE
);


CREATE TABLE "iot_OrganUserRole" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_OrganUserRole" PRIMARY KEY,
    "IsReadOnly" INTEGER NOT NULL,
    "OrganUserId" TEXT NOT NULL,
    "OrganRoleId" TEXT NOT NULL,
    "IsDeleted" TEXT NULL,
    CONSTRAINT "FK_iot_OrganUserRole_iot_OrganRole_OrganRoleId" FOREIGN KEY ("OrganRoleId") REFERENCES "iot_OrganRole" ("Id") ON DELETE CASCADE,
    CONSTRAINT "FK_iot_OrganUserRole_iot_OrganUser_OrganUserId" FOREIGN KEY ("OrganUserId") REFERENCES "iot_OrganUser" ("Id") ON DELETE CASCADE
);


CREATE TABLE "iot_Permission" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_Permission" PRIMARY KEY,
    "Name" TEXT NOT NULL,
    "Number" TEXT NOT NULL,
    "IsReadOnly" INTEGER NOT NULL,
    "Type" INTEGER NOT NULL,
    "CategoryId" TEXT NULL,
    "IsDeleted" TEXT NULL,
    CONSTRAINT "FK_iot_Permission_iot_PermissionCategory_CategoryId" FOREIGN KEY ("CategoryId") REFERENCES "iot_PermissionCategory" ("Id") ON DELETE SET NULL
);


CREATE TABLE "iot_Job" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_Job" PRIMARY KEY,
    "Name" TEXT NULL,
    "Level" INTEGER NOT NULL,
    "TitleId" TEXT NOT NULL,
    "DepartmentId" TEXT NOT NULL,
    "IsDeleted" TEXT NULL,
    CONSTRAINT "FK_iot_Job_iot_Department_DepartmentId" FOREIGN KEY ("DepartmentId") REFERENCES "iot_Department" ("Id") ON DELETE CASCADE,
    CONSTRAINT "FK_iot_Job_iot_Title_TitleId" FOREIGN KEY ("TitleId") REFERENCES "iot_Title" ("Id") ON DELETE CASCADE
);


CREATE TABLE "iot_IoTParameter" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_IoTParameter" PRIMARY KEY,
    "Type" TEXT NULL,
    "Name" TEXT NULL,
    "Description" TEXT NULL,
    "Required" INTEGER NOT NULL,
    "Maxinum" TEXT NULL,
    "Minimum" TEXT NULL,
    "IoTApiId" TEXT NOT NULL,
    "IsDeleted" TEXT NULL,
    CONSTRAINT "FK_iot_IoTParameter_iot_IoTApi_IoTApiId" FOREIGN KEY ("IoTApiId") REFERENCES "iot_IoTApi" ("Id") ON DELETE CASCADE
);


CREATE TABLE "iot_IoTDevice" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_IoTDevice" PRIMARY KEY,
    "Name" TEXT NULL,
    "Number" TEXT NOT NULL,
    "Gateway" TEXT NULL,
    "DisplayName" TEXT NOT NULL,
    "Tag" TEXT NULL,
    "IsOnline" INTEGER NOT NULL,
    "Icon" TEXT NULL,
    "Ip" TEXT NULL,
    "UserName" TEXT NULL,
    "Password" TEXT NULL,
    "ConnectId" TEXT NULL,
    "DisplayOrder" INTEGER NOT NULL,
    "Disabled" INTEGER NOT NULL,
    "IoTProductId" TEXT NOT NULL,
    "IoTGatewayId" TEXT NOT NULL,
    "IsDeleted" TEXT NULL,
    CONSTRAINT "FK_iot_IoTDevice_iot_IoTGateway_IoTGatewayId" FOREIGN KEY ("IoTGatewayId") REFERENCES "iot_IoTGateway" ("Id") ON DELETE CASCADE,
    CONSTRAINT "FK_iot_IoTDevice_iot_IoTProduct_IoTProductId" FOREIGN KEY ("IoTProductId") REFERENCES "iot_IoTProduct" ("Id") ON DELETE CASCADE
);


CREATE TABLE "iot_IoTTimer" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_IoTTimer" PRIMARY KEY,
    "Name" TEXT NULL,
    "Cron" TEXT NULL,
    "Disabled" INTEGER NOT NULL,
    "IoTSceneId" TEXT NOT NULL,
    "IsDeleted" TEXT NULL,
    CONSTRAINT "FK_iot_IoTTimer_iot_IoTScene_IoTSceneId" FOREIGN KEY ("IoTSceneId") REFERENCES "iot_IoTScene" ("Id") ON DELETE CASCADE
);


CREATE TABLE "iot_OrganRolePermission" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_OrganRolePermission" PRIMARY KEY,
    "RoleId" TEXT NOT NULL,
    "PermissionId" TEXT NOT NULL,
    "IsReadOnly" INTEGER NOT NULL,
    "IsDeleted" TEXT NULL,
    CONSTRAINT "FK_iot_OrganRolePermission_iot_OrganRole_RoleId" FOREIGN KEY ("RoleId") REFERENCES "iot_OrganRole" ("Id") ON DELETE CASCADE,
    CONSTRAINT "FK_iot_OrganRolePermission_iot_Permission_PermissionId" FOREIGN KEY ("PermissionId") REFERENCES "iot_Permission" ("Id") ON DELETE CASCADE
);


CREATE TABLE "iot_DepartmentUser" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_DepartmentUser" PRIMARY KEY,
    "Position" TEXT NULL,
    "Type" INTEGER NOT NULL,
    "CustomType" TEXT NULL,
    "UserId" TEXT NOT NULL,
    "DeparementId" TEXT NOT NULL,
    "JobId" TEXT NULL,
    "DepartmentId" TEXT NULL,
    "OrganUserId" TEXT NULL,
    "IsDeleted" TEXT NULL,
    CONSTRAINT "FK_iot_DepartmentUser_iot_Department_DepartmentId" FOREIGN KEY ("DepartmentId") REFERENCES "iot_Department" ("Id") ON DELETE RESTRICT,
    CONSTRAINT "FK_iot_DepartmentUser_iot_Job_JobId" FOREIGN KEY ("JobId") REFERENCES "iot_Job" ("Id") ON DELETE RESTRICT,
    CONSTRAINT "FK_iot_DepartmentUser_iot_OrganUser_OrganUserId" FOREIGN KEY ("OrganUserId") REFERENCES "iot_OrganUser" ("Id") ON DELETE RESTRICT,
    CONSTRAINT "FK_iot_DepartmentUser_iot_User_UserId" FOREIGN KEY ("UserId") REFERENCES "iot_User" ("Id") ON DELETE CASCADE
);


CREATE TABLE "iot_IoTCommand" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_IoTCommand" PRIMARY KEY,
    "Name" TEXT NULL,
    "DisplayOrder" INTEGER NOT NULL,
    "Disabled" INTEGER NOT NULL,
    "Delay" INTEGER NOT NULL,
    "QueryString" TEXT NULL,
    "ApiId" TEXT NOT NULL,
    "DeviceId" TEXT NOT NULL,
    "IsDeleted" TEXT NULL,
    CONSTRAINT "FK_iot_IoTCommand_iot_IoTApi_ApiId" FOREIGN KEY ("ApiId") REFERENCES "iot_IoTApi" ("Id") ON DELETE CASCADE,
    CONSTRAINT "FK_iot_IoTCommand_iot_IoTDevice_DeviceId" FOREIGN KEY ("DeviceId") REFERENCES "iot_IoTDevice" ("Id") ON DELETE CASCADE
);


CREATE TABLE "iot_IoTData" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_IoTData" PRIMARY KEY,
    "Key" TEXT NOT NULL,
    "Value" TEXT NULL,
    "Name" TEXT NULL,
    "Type" INTEGER NOT NULL,
    "Unit" TEXT NULL,
    "Description" TEXT NULL,
    "Timestamp" INTEGER NOT NULL,
    "Hidden" INTEGER NOT NULL,
    "IoTDeviceId" TEXT NOT NULL,
    "IsDeleted" TEXT NULL,
    CONSTRAINT "FK_iot_IoTData_iot_IoTDevice_IoTDeviceId" FOREIGN KEY ("IoTDeviceId") REFERENCES "iot_IoTDevice" ("Id") ON DELETE CASCADE
);


CREATE TABLE "iot_IoTSceneIoTCommand" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_IoTSceneIoTCommand" PRIMARY KEY,
    "IoTSceneId" TEXT NOT NULL,
    "IoTCommandId" TEXT NOT NULL,
    "IsDeleted" TEXT NULL,
    CONSTRAINT "FK_iot_IoTSceneIoTCommand_iot_IoTCommand_IoTCommandId" FOREIGN KEY ("IoTCommandId") REFERENCES "iot_IoTCommand" ("Id") ON DELETE CASCADE,
    CONSTRAINT "FK_iot_IoTSceneIoTCommand_iot_IoTScene_IoTSceneId" FOREIGN KEY ("IoTSceneId") REFERENCES "iot_IoTScene" ("Id") ON DELETE CASCADE
);


CREATE TABLE "iot_IoTTigger" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_iot_IoTTigger" PRIMARY KEY,
    "Name" TEXT NULL,
    "Type" INTEGER NOT NULL,
    "Condition" TEXT NULL,
    "Start" TEXT NOT NULL,
    "End" TEXT NOT NULL,
    "Disabled" INTEGER NOT NULL,
    "IoTDataId" TEXT NOT NULL,
    "IoTSceneId" TEXT NOT NULL,
    "IoTDataId1" TEXT NULL,
    "IsDeleted" TEXT NULL,
    CONSTRAINT "FK_iot_IoTTigger_iot_IoTData_IoTDataId" FOREIGN KEY ("IoTDataId") REFERENCES "iot_IoTData" ("Id") ON DELETE CASCADE,
    CONSTRAINT "FK_iot_IoTTigger_iot_IoTData_IoTDataId1" FOREIGN KEY ("IoTDataId1") REFERENCES "iot_IoTData" ("Id") ON DELETE RESTRICT,
    CONSTRAINT "FK_iot_IoTTigger_iot_IoTScene_IoTSceneId" FOREIGN KEY ("IoTSceneId") REFERENCES "iot_IoTScene" ("Id") ON DELETE CASCADE
);


CREATE UNIQUE INDEX "IX_iot_Area_Number" ON "iot_Area" ("Number");


CREATE INDEX "IX_iot_Area_ParentId" ON "iot_Area" ("ParentId");


CREATE INDEX "IX_iot_Building_AreaId" ON "iot_Building" ("AreaId");


CREATE UNIQUE INDEX "IX_iot_Building_OrganId_ParentId_Number" ON "iot_Building" ("OrganId", "ParentId", "Number");


CREATE INDEX "IX_iot_Building_ParentId" ON "iot_Building" ("ParentId");


CREATE UNIQUE INDEX "IX_iot_Department_OrganId_Number" ON "iot_Department" ("OrganId", "Number");


CREATE INDEX "IX_iot_Department_ParentId" ON "iot_Department" ("ParentId");


CREATE INDEX "IX_iot_DepartmentUser_DepartmentId" ON "iot_DepartmentUser" ("DepartmentId");


CREATE INDEX "IX_iot_DepartmentUser_JobId" ON "iot_DepartmentUser" ("JobId");


CREATE INDEX "IX_iot_DepartmentUser_OrganUserId" ON "iot_DepartmentUser" ("OrganUserId");


CREATE INDEX "IX_iot_DepartmentUser_UserId" ON "iot_DepartmentUser" ("UserId");


CREATE UNIQUE INDEX "IX_iot_IoTApi_IoTProductId_Name" ON "iot_IoTApi" ("IoTProductId", "Name");


CREATE INDEX "IX_iot_IoTCommand_ApiId" ON "iot_IoTCommand" ("ApiId");


CREATE INDEX "IX_iot_IoTCommand_DeviceId" ON "iot_IoTCommand" ("DeviceId");


CREATE INDEX "IX_iot_IoTData_IoTDeviceId" ON "iot_IoTData" ("IoTDeviceId");


CREATE INDEX "IX_iot_IoTDevice_IoTGatewayId" ON "iot_IoTDevice" ("IoTGatewayId");


CREATE INDEX "IX_iot_IoTDevice_IoTProductId" ON "iot_IoTDevice" ("IoTProductId");


CREATE UNIQUE INDEX "IX_iot_IoTDevice_Number" ON "iot_IoTDevice" ("Number");


CREATE INDEX "IX_iot_IoTGateway_BuildingId" ON "iot_IoTGateway" ("BuildingId");


CREATE UNIQUE INDEX "IX_iot_IoTGateway_Number" ON "iot_IoTGateway" ("Number");


CREATE INDEX "IX_iot_IoTParameter_IoTApiId" ON "iot_IoTParameter" ("IoTApiId");


CREATE INDEX "IX_iot_IoTProduct_IoTProductCategoryId" ON "iot_IoTProduct" ("IoTProductCategoryId");


CREATE UNIQUE INDEX "IX_iot_IoTProduct_Number" ON "iot_IoTProduct" ("Number");


CREATE UNIQUE INDEX "IX_iot_IoTProductCategory_Number" ON "iot_IoTProductCategory" ("Number");


CREATE INDEX "IX_iot_IoTProductCategory_ParentId" ON "iot_IoTProductCategory" ("ParentId");


CREATE INDEX "IX_iot_IoTScene_BuildingId" ON "iot_IoTScene" ("BuildingId");


CREATE INDEX "IX_iot_IoTSceneIoTCommand_IoTCommandId" ON "iot_IoTSceneIoTCommand" ("IoTCommandId");


CREATE INDEX "IX_iot_IoTSceneIoTCommand_IoTSceneId" ON "iot_IoTSceneIoTCommand" ("IoTSceneId");


CREATE INDEX "IX_iot_IoTTigger_IoTDataId" ON "iot_IoTTigger" ("IoTDataId");


CREATE INDEX "IX_iot_IoTTigger_IoTDataId1" ON "iot_IoTTigger" ("IoTDataId1");


CREATE INDEX "IX_iot_IoTTigger_IoTSceneId" ON "iot_IoTTigger" ("IoTSceneId");


CREATE INDEX "IX_iot_IoTTimer_IoTSceneId" ON "iot_IoTTimer" ("IoTSceneId");


CREATE INDEX "IX_iot_Job_DepartmentId" ON "iot_Job" ("DepartmentId");


CREATE INDEX "IX_iot_Job_TitleId" ON "iot_Job" ("TitleId");


CREATE INDEX "IX_iot_Organ_AreaId" ON "iot_Organ" ("AreaId");


CREATE UNIQUE INDEX "IX_iot_Organ_Name" ON "iot_Organ" ("Name");


CREATE UNIQUE INDEX "IX_iot_Organ_Number" ON "iot_Organ" ("Number");


CREATE INDEX "IX_iot_Organ_ParentId" ON "iot_Organ" ("ParentId");


CREATE UNIQUE INDEX "IX_iot_OrganRole_OrganId_Number" ON "iot_OrganRole" ("OrganId", "Number");


CREATE INDEX "IX_iot_OrganRolePermission_PermissionId" ON "iot_OrganRolePermission" ("PermissionId");


CREATE UNIQUE INDEX "IX_iot_OrganRolePermission_RoleId_PermissionId" ON "iot_OrganRolePermission" ("RoleId", "PermissionId");


CREATE UNIQUE INDEX "IX_iot_OrganUser_OrganId_UserId" ON "iot_OrganUser" ("OrganId", "UserId");


CREATE INDEX "IX_iot_OrganUser_UserId" ON "iot_OrganUser" ("UserId");


CREATE INDEX "IX_iot_OrganUserRole_OrganRoleId" ON "iot_OrganUserRole" ("OrganRoleId");


CREATE UNIQUE INDEX "IX_iot_OrganUserRole_OrganUserId_OrganRoleId" ON "iot_OrganUserRole" ("OrganUserId", "OrganRoleId");


CREATE INDEX "IX_iot_Permission_CategoryId" ON "iot_Permission" ("CategoryId");


CREATE UNIQUE INDEX "IX_iot_Permission_Number" ON "iot_Permission" ("Number");


CREATE INDEX "IX_iot_PermissionCategory_OrganId" ON "iot_PermissionCategory" ("OrganId");


CREATE INDEX "IX_iot_PermissionCategory_ParentId" ON "iot_PermissionCategory" ("ParentId");


CREATE UNIQUE INDEX "IX_iot_Setting_Name" ON "iot_Setting" ("Name");


CREATE UNIQUE INDEX "IX_iot_Site_Name" ON "iot_Site" ("Name");


CREATE INDEX "IX_iot_Title_OrganId" ON "iot_Title" ("OrganId");


CREATE UNIQUE INDEX "IX_iot_User_Email" ON "iot_User" ("Email");


CREATE UNIQUE INDEX "IX_iot_User_PhoneNumber" ON "iot_User" ("PhoneNumber");


CREATE UNIQUE INDEX "IX_iot_User_UserName" ON "iot_User" ("UserName");


