Skip to content

Commit

Permalink
feat: add UNIQUE CONSTRAINT INDEX for each table
Browse files Browse the repository at this point in the history
  • Loading branch information
nisiyong committed Sep 4, 2021
1 parent d7d81a7 commit e49082c
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

Use ApolloConfigDB;

UPDATE `AccessKey` SET `DeletedAt` = -Id WHERE `IsDeleted` = 1 and `DeletedAt` = 0;
UPDATE `App` SET `DeletedAt` = -Id WHERE `IsDeleted` = 1 and `DeletedAt` = 0;
UPDATE `AppNamespace` SET `DeletedAt` = -Id WHERE `IsDeleted` = 1 and `DeletedAt` = 0;
UPDATE `Audit` SET `DeletedAt` = -Id WHERE `IsDeleted` = 1 and `DeletedAt` = 0;
Expand All @@ -29,6 +30,48 @@ UPDATE `NamespaceLock` SET `DeletedAt` = -Id WHERE `IsDeleted` = 1 and `DeletedA
UPDATE `Release` SET `DeletedAt` = -Id WHERE `IsDeleted` = 1 and `DeletedAt` = 0;
UPDATE `ReleaseHistory` SET `DeletedAt` = -Id WHERE `IsDeleted` = 1 and `DeletedAt` = 0;
UPDATE `ServerConfig` SET `DeletedAt` = -Id WHERE `IsDeleted` = 1 and `DeletedAt` = 0;
UPDATE `AccessKey` SET `DeletedAt` = -Id WHERE `IsDeleted` = 1 and `DeletedAt` = 0;

-- TODO: add UNIQUE CONSTRAINT INDEX for each table
-- add UNIQUE CONSTRAINT INDEX for each table
ALTER TABLE `AccessKey`
ADD UNIQUE INDEX `UK_AppId_Secret_DeletedAt` (`AppId`,`Secret`,`DeletedAt`),
DROP INDEX `AppId`;

ALTER TABLE `App`
ADD UNIQUE INDEX `UK_AppId_DeletedAt` (`AppId`,`DeletedAt`),
DROP INDEX `AppId`;

ALTER TABLE `AppNamespace`
ADD UNIQUE INDEX `UK_AppId_Name_DeletedAt` (`AppId`,`Name`,`DeletedAt`),
DROP INDEX `IX_AppId`;

-- Ignore TABLE `Audit`

ALTER TABLE `Cluster`
ADD UNIQUE INDEX `UK_AppId_Name_DeletedAt` (`AppId`,`Name`,`DeletedAt`),
DROP INDEX `IX_AppId_Name`;

-- Ignore TABLE `Commit`

-- TODO: ALTER TABLE `GrayReleaseRule`

ALTER TABLE `Item`
ADD UNIQUE INDEX `UK_NamespaceId_Key_DeletedAt` (`NamespaceId`,`Key`,`DeletedAt`),
DROP INDEX `IX_GroupId`;

ALTER TABLE `Namespace`
ADD UNIQUE INDEX `UK_AppId_ClusterName_NamespaceName_DeletedAt` (`AppId`,`ClusterName`,`NamespaceName`,`DeletedAt`),
DROP INDEX `AppId_ClusterName_NamespaceName`;

ALTER TABLE `NamespaceLock`
ADD UNIQUE INDEX `UK_NamespaceId_DeletedAt` (`NamespaceId`,`DeletedAt`),
DROP INDEX `IX_NamespaceId`;

ALTER TABLE `Release`
ADD UNIQUE INDEX `UK_ReleaseKey_DeletedAt` (`ReleaseKey`,`DeletedAt`),
DROP INDEX `IX_ReleaseKey`;

-- TODO: ALTER TABLE `ReleaseHistory`

ALTER TABLE `ServerConfig`
ADD UNIQUE INDEX `UK_Key_DeletedAt` (`Key`,`DeletedAt`),
DROP INDEX `IX_Key`;
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,42 @@ UPDATE `RolePermission` SET `DeletedAt` = -Id WHERE `IsDeleted` = 1 and `Deleted
UPDATE `ServerConfig` SET `DeletedAt` = -Id WHERE `IsDeleted` = 1 and `DeletedAt` = 0;
UPDATE `UserRole` SET `DeletedAt` = -Id WHERE `IsDeleted` = 1 and `DeletedAt` = 0;

-- TODO: add UNIQUE CONSTRAINT INDEX for each table
-- add UNIQUE CONSTRAINT INDEX for each table
ALTER TABLE `App`
ADD UNIQUE INDEX `UK_AppId_DeletedAt` (`AppId`,`DeletedAt`),
DROP INDEX `AppId`;

ALTER TABLE `AppNamespace`
ADD UNIQUE INDEX `UK_AppId_Name_DeletedAt` (`AppId`,`Name`,`DeletedAt`),
DROP INDEX `IX_AppId`;

-- TODO: ALTER TABLE `Consumer`
-- TODO: ALTER TABLE `ConsumerRole`
-- TODO: ALTER TABLE `ConsumerToken`

ALTER TABLE `Favorite`
ADD UNIQUE INDEX `UK_UserId_AppId_DeletedAt` (`UserId`,`AppId`,`DeletedAt`),
DROP INDEX `IX_UserId`;

ALTER TABLE `Permission`
ADD UNIQUE INDEX `UK_TargetId_PermissionType_DeletedAt` (`TargetId`,`PermissionType`,`DeletedAt`),
DROP INDEX `IX_TargetId_PermissionType`;

ALTER TABLE `Role`
ADD UNIQUE INDEX `UK_RoleName_DeletedAt` (`RoleName`,`DeletedAt`),
DROP INDEX `IX_RoleName`;

ALTER TABLE `RolePermission`
ADD UNIQUE INDEX `UK_RoleId_PermissionId_DeletedAt` (`RoleId`,`PermissionId`,`DeletedAt`),
DROP INDEX `IX_RoleId`;

ALTER TABLE `ServerConfig`
ADD UNIQUE INDEX `UK_Key_DeletedAt` (`Key`,`DeletedAt`),
DROP INDEX `IX_Key`;

ALTER TABLE `UserRole`
ADD UNIQUE INDEX `UK_UserId_RoleId_DeletedAt` (`UserId`,`RoleId`,`DeletedAt`),
DROP INDEX `IX_UserId_RoleId`;

ALTER TABLE `Users`
ADD UNIQUE INDEX `UK_Username` (`Username`);

0 comments on commit e49082c

Please sign in to comment.