CREATE TABLE "uc_Department" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_uc_Department" PRIMARY KEY,
    "IsDeleted" TEXT NULL,
    "Name" TEXT NULL,
    "Number" TEXT NOT NULL,
    "Path" TEXT NULL,
    "ParentId" TEXT NULL,
    CONSTRAINT "FK_uc_Department_uc_Department_ParentId" FOREIGN KEY ("ParentId") REFERENCES "uc_Department" ("Id") ON DELETE RESTRICT
);

CREATE TABLE "uc_PermissionCategory" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_uc_PermissionCategory" PRIMARY KEY,
    "IsDeleted" TEXT NULL,
    "Name" TEXT NULL,
    "Number" TEXT NULL,
    "Path" TEXT NULL,
    "ParentId" TEXT NULL,
    CONSTRAINT "FK_uc_PermissionCategory_uc_PermissionCategory_ParentId" FOREIGN KEY ("ParentId") REFERENCES "uc_PermissionCategory" ("Id") ON DELETE SET NULL
);

CREATE TABLE "uc_Role" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_uc_Role" PRIMARY KEY,
    "IsDeleted" TEXT NULL,
    "Name" TEXT NULL,
    "IsReadOnly" INTEGER NOT NULL
);

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

CREATE TABLE "uc_Site" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_uc_Site" PRIMARY KEY,
    "IsDeleted" TEXT NULL,
    "Name" TEXT NULL,
    "Icon" TEXT NULL,
    "Description" TEXT NULL,
    "Key" TEXT NULL,
    "Home" TEXT NULL,
    "Login" TEXT NULL,
    "Logout" TEXT NULL
);

CREATE TABLE "uc_User" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_uc_User" PRIMARY KEY,
    "IsDeleted" TEXT NULL,
    "UserName" TEXT NULL,
    "SecurityStamp" TEXT NULL,
    "PasswordHash" TEXT NULL,
    "PasswordConfirmed" INTEGER NOT NULL,
    "Email" TEXT NULL,
    "EmailConfirmed" INTEGER NOT NULL,
    "PhoneNumberConfirmed" INTEGER NOT NULL,
    "PhoneNumber" TEXT NULL,
    "PayPassword" TEXT NULL,
    "PayPasswordConfirmed" INTEGER NOT NULL,
    "RealName" TEXT NULL,
    "IdCardNumber" TEXT NULL,
    "IdentityConfirmed" INTEGER NOT NULL,
    "NickName" TEXT NULL,
    "Avatar" TEXT NULL,
    "FaceImage" TEXT NULL,
    "Sex" INTEGER NOT NULL,
    "Birthday" TEXT NULL,
    "AvailBalance" TEXT NOT NULL,
    "FrozenBlance" TEXT NOT NULL,
    "Point" INTEGER NOT NULL,
    "LockoutEnabled" INTEGER NOT NULL,
    "AccessFailedCount" INTEGER NOT NULL,
    "LockoutEnd" TEXT NULL,
    "RowVersion" TEXT NULL
);

CREATE TABLE "uc_Permission" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_uc_Permission" PRIMARY KEY,
    "IsDeleted" TEXT NULL,
    "Name" TEXT NULL,
    "Number" TEXT NULL,
    "CategoryId" TEXT NULL,
    CONSTRAINT "FK_uc_Permission_uc_PermissionCategory_CategoryId" FOREIGN KEY ("CategoryId") REFERENCES "uc_PermissionCategory" ("Id") ON DELETE SET NULL
);

CREATE TABLE "uc_UserDepartment" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_uc_UserDepartment" PRIMARY KEY,
    "IsDeleted" TEXT NULL,
    "UserId" TEXT NOT NULL,
    "DepartmentId" TEXT NOT NULL,
    CONSTRAINT "FK_uc_UserDepartment_uc_Department_DepartmentId" FOREIGN KEY ("DepartmentId") REFERENCES "uc_Department" ("Id") ON DELETE CASCADE,
    CONSTRAINT "FK_uc_UserDepartment_uc_User_UserId" FOREIGN KEY ("UserId") REFERENCES "uc_User" ("Id") ON DELETE CASCADE
);

CREATE TABLE "uc_UserRole" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_uc_UserRole" PRIMARY KEY,
    "IsDeleted" TEXT NULL,
    "UserId" TEXT NOT NULL,
    "RoleId" TEXT NOT NULL,
    CONSTRAINT "FK_uc_UserRole_uc_Role_RoleId" FOREIGN KEY ("RoleId") REFERENCES "uc_Role" ("Id") ON DELETE CASCADE,
    CONSTRAINT "FK_uc_UserRole_uc_User_UserId" FOREIGN KEY ("UserId") REFERENCES "uc_User" ("Id") ON DELETE CASCADE
);

CREATE TABLE "uc_RolePermission" (
    "Id" TEXT NOT NULL CONSTRAINT "PK_uc_RolePermission" PRIMARY KEY,
    "IsDeleted" TEXT NULL,
    "RoleId" TEXT NOT NULL,
    "PermissionId" TEXT NOT NULL,
    "IsReadOnly" INTEGER NOT NULL,
    CONSTRAINT "FK_uc_RolePermission_uc_Permission_PermissionId" FOREIGN KEY ("PermissionId") REFERENCES "uc_Permission" ("Id") ON DELETE CASCADE,
    CONSTRAINT "FK_uc_RolePermission_uc_Role_RoleId" FOREIGN KEY ("RoleId") REFERENCES "uc_Role" ("Id") ON DELETE CASCADE
);

CREATE UNIQUE INDEX "IX_uc_Department_Number" ON "uc_Department" ("Number");

CREATE INDEX "IX_uc_Department_ParentId" ON "uc_Department" ("ParentId");

CREATE INDEX "IX_uc_Permission_CategoryId" ON "uc_Permission" ("CategoryId");

CREATE UNIQUE INDEX "IX_uc_Permission_Number" ON "uc_Permission" ("Number");

CREATE UNIQUE INDEX "IX_uc_PermissionCategory_Number" ON "uc_PermissionCategory" ("Number");

CREATE INDEX "IX_uc_PermissionCategory_ParentId" ON "uc_PermissionCategory" ("ParentId");

CREATE UNIQUE INDEX "IX_uc_Role_Name" ON "uc_Role" ("Name");

CREATE INDEX "IX_uc_RolePermission_PermissionId" ON "uc_RolePermission" ("PermissionId");

CREATE UNIQUE INDEX "IX_uc_RolePermission_RoleId_PermissionId" ON "uc_RolePermission" ("RoleId", "PermissionId");

CREATE UNIQUE INDEX "IX_uc_Site_Name" ON "uc_Site" ("Name");

CREATE UNIQUE INDEX "IX_uc_User_NickName" ON "uc_User" ("NickName");

CREATE UNIQUE INDEX "IX_uc_User_PhoneNumber" ON "uc_User" ("PhoneNumber");

CREATE INDEX "IX_uc_UserDepartment_DepartmentId" ON "uc_UserDepartment" ("DepartmentId");

CREATE UNIQUE INDEX "IX_uc_UserDepartment_UserId_DepartmentId" ON "uc_UserDepartment" ("UserId", "DepartmentId");

CREATE INDEX "IX_uc_UserRole_RoleId" ON "uc_UserRole" ("RoleId");

CREATE UNIQUE INDEX "IX_uc_UserRole_UserId_RoleId" ON "uc_UserRole" ("UserId", "RoleId");

