mirror of
https://github.com/harness/drone.git
synced 2025-05-04 14:43:15 +08:00
feat: [CDE-390]:add can delete column in gitspace_config table (#2827)
* fix err msg * update migration query * fix typo * feedback comments * add can delete column in gitspace_config table
This commit is contained in:
parent
5cbd33bd5d
commit
21bdad8ece
@ -39,16 +39,19 @@ func (c *Controller) Delete(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to find space: %w", err)
|
return fmt.Errorf("failed to find space: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = apiauth.CheckGitspace(ctx, c.authorizer, session, space.Path, identifier, enum.PermissionGitspaceDelete)
|
err = apiauth.CheckGitspace(ctx, c.authorizer, session, space.Path, identifier, enum.PermissionGitspaceDelete)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to authorize: %w", err)
|
return fmt.Errorf("failed to authorize: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gitspaceConfig, err := c.gitspaceConfigStore.FindByIdentifier(ctx, space.ID, identifier)
|
gitspaceConfig, err := c.gitspaceConfigStore.FindByIdentifier(ctx, space.ID, identifier)
|
||||||
gitspaceConfig.SpacePath = space.Path
|
gitspaceConfig.SpacePath = space.Path
|
||||||
if err != nil || gitspaceConfig == nil {
|
if err != nil || gitspaceConfig == nil {
|
||||||
log.Err(err).Msg(gitspaceConfigNotFound + identifier)
|
log.Err(err).Msg(gitspaceConfigNotFound + identifier)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
instance, _ := c.gitspaceInstanceStore.FindLatestByGitspaceConfigID(ctx, gitspaceConfig.ID)
|
instance, _ := c.gitspaceInstanceStore.FindLatestByGitspaceConfigID(ctx, gitspaceConfig.ID)
|
||||||
gitspaceConfig.GitspaceInstance = instance
|
gitspaceConfig.GitspaceInstance = instance
|
||||||
if instance == nil || instance.State == enum.GitspaceInstanceStateUninitialized {
|
if instance == nil || instance.State == enum.GitspaceInstanceStateUninitialized {
|
||||||
@ -56,10 +59,18 @@ func (c *Controller) Delete(
|
|||||||
if err = c.gitspaceSvc.UpdateConfig(ctx, gitspaceConfig); err != nil {
|
if err = c.gitspaceSvc.UpdateConfig(ctx, gitspaceConfig); err != nil {
|
||||||
return fmt.Errorf("failed to mark gitspace config as deleted: %w", err)
|
return fmt.Errorf("failed to mark gitspace config as deleted: %w", err)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// mark can_delete for gitconfig as true so that if delete operation fails, cron job can clean up resources.
|
||||||
|
gitspaceConfig.IsMarkedForDeletion = true
|
||||||
|
if err = c.gitspaceSvc.UpdateConfig(ctx, gitspaceConfig); err != nil {
|
||||||
|
return fmt.Errorf("failed to mark gitspace config is_marked_for_deletion column: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
ctxWithoutCancel := context.WithoutCancel(ctx)
|
ctxWithoutCancel := context.WithoutCancel(ctx)
|
||||||
go c.removeGitspace(ctxWithoutCancel, *gitspaceConfig)
|
go c.removeGitspace(ctxWithoutCancel, *gitspaceConfig)
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,8 @@ const (
|
|||||||
gconf_is_deleted,
|
gconf_is_deleted,
|
||||||
gconf_code_repo_ref,
|
gconf_code_repo_ref,
|
||||||
gconf_ssh_token_identifier,
|
gconf_ssh_token_identifier,
|
||||||
gconf_created_by
|
gconf_created_by,
|
||||||
|
gconf_is_marked_for_deletion
|
||||||
`
|
`
|
||||||
gitspaceConfigsTable = `gitspace_configs`
|
gitspaceConfigsTable = `gitspace_configs`
|
||||||
ReturningClause = "RETURNING "
|
ReturningClause = "RETURNING "
|
||||||
@ -80,6 +81,7 @@ type gitspaceConfig struct {
|
|||||||
IsDeleted bool `db:"gconf_is_deleted"`
|
IsDeleted bool `db:"gconf_is_deleted"`
|
||||||
SSHTokenIdentifier string `db:"gconf_ssh_token_identifier"`
|
SSHTokenIdentifier string `db:"gconf_ssh_token_identifier"`
|
||||||
CreatedBy null.Int `db:"gconf_created_by"`
|
CreatedBy null.Int `db:"gconf_created_by"`
|
||||||
|
IsMarkedForDeletion bool `db:"gconf_is_marked_for_deletion"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ store.GitspaceConfigStore = (*gitspaceConfigStore)(nil)
|
var _ store.GitspaceConfigStore = (*gitspaceConfigStore)(nil)
|
||||||
@ -197,6 +199,7 @@ func (s gitspaceConfigStore) Create(ctx context.Context, gitspaceConfig *types.G
|
|||||||
gitspaceConfig.CodeRepo.Ref,
|
gitspaceConfig.CodeRepo.Ref,
|
||||||
gitspaceConfig.SSHTokenIdentifier,
|
gitspaceConfig.SSHTokenIdentifier,
|
||||||
gitspaceConfig.GitspaceUser.ID,
|
gitspaceConfig.GitspaceUser.ID,
|
||||||
|
gitspaceConfig.IsMarkedForDeletion,
|
||||||
).
|
).
|
||||||
Suffix(ReturningClause + "gconf_id")
|
Suffix(ReturningClause + "gconf_id")
|
||||||
sql, args, err := stmt.ToSql()
|
sql, args, err := stmt.ToSql()
|
||||||
@ -221,6 +224,7 @@ func (s gitspaceConfigStore) Update(ctx context.Context,
|
|||||||
Set("gconf_updated", dbGitspaceConfig.Updated).
|
Set("gconf_updated", dbGitspaceConfig.Updated).
|
||||||
Set("gconf_infra_provider_resource_id", dbGitspaceConfig.InfraProviderResourceID).
|
Set("gconf_infra_provider_resource_id", dbGitspaceConfig.InfraProviderResourceID).
|
||||||
Set("gconf_is_deleted", dbGitspaceConfig.IsDeleted).
|
Set("gconf_is_deleted", dbGitspaceConfig.IsDeleted).
|
||||||
|
Set("gconf_is_marked_for_deletion", dbGitspaceConfig.IsMarkedForDeletion).
|
||||||
Where("gconf_id = ?", gitspaceConfig.ID)
|
Where("gconf_id = ?", gitspaceConfig.ID)
|
||||||
sql, args, err := stmt.ToSql()
|
sql, args, err := stmt.ToSql()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -252,6 +256,7 @@ func mapToInternalGitspaceConfig(config *types.GitspaceConfig) *gitspaceConfig {
|
|||||||
UserUID: config.GitspaceUser.Identifier,
|
UserUID: config.GitspaceUser.Identifier,
|
||||||
SpaceID: config.SpaceID,
|
SpaceID: config.SpaceID,
|
||||||
IsDeleted: config.IsDeleted,
|
IsDeleted: config.IsDeleted,
|
||||||
|
IsMarkedForDeletion: config.IsMarkedForDeletion,
|
||||||
Created: config.Created,
|
Created: config.Created,
|
||||||
Updated: config.Updated,
|
Updated: config.Updated,
|
||||||
SSHTokenIdentifier: config.SSHTokenIdentifier,
|
SSHTokenIdentifier: config.SSHTokenIdentifier,
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE gitspace_configs
|
||||||
|
DROP COLUMN gconf_is_marked_for_deletion;
|
@ -0,0 +1,5 @@
|
|||||||
|
ALTER TABLE gitspace_configs
|
||||||
|
ADD COLUMN gconf_is_marked_for_deletion BOOLEAN NOT NULL DEFAULT FALSE;
|
||||||
|
|
||||||
|
UPDATE gitspace_configs
|
||||||
|
SET gconf_is_marked_for_deletion = gconf_is_deleted;
|
@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE gitspace_configs
|
||||||
|
DROP COLUMN gconf_is_marked_for_deletion;
|
@ -0,0 +1,5 @@
|
|||||||
|
ALTER TABLE gitspace_configs
|
||||||
|
ADD COLUMN gconf_is_marked_for_deletion BOOLEAN NOT NULL DEFAULT FALSE;
|
||||||
|
|
||||||
|
UPDATE gitspace_configs
|
||||||
|
SET gconf_is_marked_for_deletion = gconf_is_deleted;
|
@ -26,6 +26,7 @@ type GitspaceConfig struct {
|
|||||||
State enum.GitspaceStateType `json:"state"`
|
State enum.GitspaceStateType `json:"state"`
|
||||||
SpaceID int64 `json:"-"`
|
SpaceID int64 `json:"-"`
|
||||||
IsDeleted bool `json:"-"`
|
IsDeleted bool `json:"-"`
|
||||||
|
IsMarkedForDeletion bool `json:"-"`
|
||||||
GitspaceInstance *GitspaceInstance `json:"instance"`
|
GitspaceInstance *GitspaceInstance `json:"instance"`
|
||||||
SpacePath string `json:"space_path"`
|
SpacePath string `json:"space_path"`
|
||||||
Created int64 `json:"created"`
|
Created int64 `json:"created"`
|
||||||
|
Loading…
Reference in New Issue
Block a user