如何删除发布后的项目(AppId)

需求

在使用携程Apollo配置中心的时候,有时候我们创建的项目仅仅用来测试,或者没用了。这时候我们想把他删除,会发现无法删除项目。

如何删除应用?

     根据官方描述

由于删除应用影响面较大,所以现在暂无删除应用功能。

此外,除了appId之外,其它app相关信息都能修改,所以不建议删除app。

如果确实需要删除应用的话,可以参照下面的sql手动删除数据库相关的表。

1.删除ApolloPortalDB中的数据

复制下面的sql内容,把第一行的appId从SampleApp改为实际要删除的appId,在ApolloPortalDB中执行即可。

set @appId = ‘SampleApp‘;
 
Use `ApolloPortalDB`;
 
update `App` set `IsDeleted` = 1 where `AppId` = @appId and `IsDeleted` = 0;
update `AppNamespace` set `IsDeleted` = 1 where `AppId` = @appId and `IsDeleted` = 0;
update `Favorite` set `IsDeleted` = 1 where `AppId` = @appId and `IsDeleted` = 0;
 
# handle roles and permissions
create temporary table `PermissionIds` as select `Id` from `Permission` where (`TargetId` = @appId or `TargetId` like CONCAT(@appId, ‘+%‘))  and `IsDeleted` = 0;
update `Permission` set `IsDeleted` = 1 where `Id` in (select `Id` from `PermissionIds`);
update `RolePermission` set `IsDeleted` = 1 where `PermissionId` in (select `Id` from `PermissionIds`);
drop temporary table `PermissionIds`;
 
create temporary table `RoleIds` as select `Id` from `Role` where (`RoleName` = CONCAT(‘Master+‘, @appId) or `RoleName` like CONCAT(‘ModifyNamespace+‘, @appId, ‘+%‘) or `RoleName` like CONCAT(‘ReleaseNamespace+‘, @appId, ‘+%‘)) and `IsDeleted` = 0;
update `Role` set `IsDeleted` = 1 where `Id` in (select `Id` from `RoleIds`);
update `UserRole` set `IsDeleted` = 1 where `RoleId` in (select `Id` from `RoleIds`);
update `ConsumerRole` set `IsDeleted` = 1 where `RoleId` in (select `Id` from `RoleIds`);

2.删除ApolloConfigDB中的数据

复制下面的sql内容,把第一行的appId从SampleApp改为实际要删除的appId,在AploolConfigDB中执行即可。

set @appId = ‘SampleApp‘;
 
Use `ApolloConfigDB`;
 
update `App` set `IsDeleted` = 1 where `AppId` = @appId and `IsDeleted` = 0;
update `AppNamespace` set `IsDeleted` = 1 where `AppId` = @appId and `IsDeleted` = 0;
update `Cluste r` set `IsDeleted` = 1 where `AppId` = @appId and `IsDeleted` = 0;
update `Commit` set `IsDeleted` = 1 where `AppId` = @appId and `IsDeleted` = 0;
update `GrayReleaseRule` set `IsDeleted` = 1 where `AppId` = @appId and `IsDeleted` = 0;
update `Release` set `IsDeleted` = 1 where `AppId` = @appId and `IsDeleted` = 0;
update `ReleaseHistory` set `IsDeleted` = 1 where `AppId` = @appId and `IsDeleted` = 0;
delete from `Instance` where `AppId` = @appId;
delete from `InstanceConfig` where `ConfigAppId` = @appId;
delete from `ReleaseMessage` where `Message` like CONCAT(@appId, ‘+%‘);
 
# handle namespaces and items
create temporary table `NamespaceIds` as select `Id` from `Namespace` where `AppId` = @appId and `IsDeleted` = 0;
update `Namespace` set `IsDeleted` = 1 where `Id` in (select `Id` from `NamespaceIds`);
update `Item` set `IsDeleted` = 1 where `NamespaceId` in (select `Id` from `NamespaceIds`);
delete from `NamespaceLock` where `NamespaceId` in (select `Id` from `NamespaceIds`);
drop temporary table `NamespaceIds`;

相关推荐