V2.0.1__add-unique-key.sql 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. --
  2. -- Copyright 2022 Apollo Authors
  3. --
  4. -- Licensed under the Apache License, Version 2.0 (the "License");
  5. -- you may not use this file except in compliance with the License.
  6. -- You may obtain a copy of the License at
  7. --
  8. -- http://www.apache.org/licenses/LICENSE-2.0
  9. --
  10. -- Unless required by applicable law or agreed to in writing, software
  11. -- distributed under the License is distributed on an "AS IS" BASIS,
  12. -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. -- See the License for the specific language governing permissions and
  14. -- limitations under the License.
  15. --
  16. # delta schema to upgrade apollo portal db from v1.9.0 to v2.0.0
  17. Use ApolloPortalDB;
  18. -- the follow DML won't change the `DataChange_LastTime` field
  19. UPDATE `App` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0;
  20. UPDATE `AppNamespace` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0;
  21. UPDATE `Consumer` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0;
  22. UPDATE `ConsumerRole` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0;
  23. UPDATE `ConsumerToken` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0;
  24. UPDATE `Favorite` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0;
  25. UPDATE `Permission` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0;
  26. UPDATE `Role` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0;
  27. UPDATE `RolePermission` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0;
  28. UPDATE `ServerConfig` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0;
  29. UPDATE `UserRole` SET `DeletedAt` = -Id, `DataChange_LastTime` = `DataChange_LastTime` WHERE `IsDeleted` = 1 and `DeletedAt` = 0;
  30. -- add UNIQUE CONSTRAINT INDEX for each table
  31. ALTER TABLE `App`
  32. ADD UNIQUE INDEX `UK_AppId_DeletedAt` (`AppId`,`DeletedAt`),
  33. DROP INDEX `AppId`;
  34. ALTER TABLE `AppNamespace`
  35. ADD UNIQUE INDEX `UK_AppId_Name_DeletedAt` (`AppId`,`Name`,`DeletedAt`),
  36. DROP INDEX `IX_AppId`;
  37. ALTER TABLE `Consumer`
  38. ADD UNIQUE INDEX `UK_AppId_DeletedAt` (`AppId`,`DeletedAt`),
  39. DROP INDEX `AppId`;
  40. ALTER TABLE `ConsumerRole`
  41. ADD UNIQUE INDEX `UK_ConsumerId_RoleId_DeletedAt` (`ConsumerId`,`RoleId`,`DeletedAt`),
  42. DROP INDEX `IX_ConsumerId_RoleId`;
  43. ALTER TABLE `ConsumerToken`
  44. ADD UNIQUE INDEX `UK_Token_DeletedAt` (`Token`,`DeletedAt`),
  45. DROP INDEX `IX_Token`;
  46. ALTER TABLE `Favorite`
  47. ADD UNIQUE INDEX `UK_UserId_AppId_DeletedAt` (`UserId`,`AppId`,`DeletedAt`),
  48. DROP INDEX `IX_UserId`;
  49. ALTER TABLE `Permission`
  50. ADD UNIQUE INDEX `UK_TargetId_PermissionType_DeletedAt` (`TargetId`,`PermissionType`,`DeletedAt`),
  51. DROP INDEX `IX_TargetId_PermissionType`;
  52. ALTER TABLE `Role`
  53. ADD UNIQUE INDEX `UK_RoleName_DeletedAt` (`RoleName`,`DeletedAt`),
  54. DROP INDEX `IX_RoleName`;
  55. ALTER TABLE `RolePermission`
  56. ADD UNIQUE INDEX `UK_RoleId_PermissionId_DeletedAt` (`RoleId`,`PermissionId`,`DeletedAt`),
  57. DROP INDEX `IX_RoleId`;
  58. ALTER TABLE `ServerConfig`
  59. ADD UNIQUE INDEX `UK_Key_DeletedAt` (`Key`,`DeletedAt`),
  60. DROP INDEX `IX_Key`;
  61. ALTER TABLE `UserRole`
  62. ADD UNIQUE INDEX `UK_UserId_RoleId_DeletedAt` (`UserId`,`RoleId`,`DeletedAt`),
  63. DROP INDEX `IX_UserId_RoleId`;
  64. ALTER TABLE `Users`
  65. ADD UNIQUE INDEX `UK_Username` (`Username`);