add migration to drop deprecated gateway columns (#2670)

* update cde gateway full sync query
* add migration to drop deprecated gateway columns
CODE-2402
Kapil Garg 2024-09-09 08:30:49 +00:00 committed by Harness
parent 370007c0f7
commit 029a033be7
9 changed files with 21 additions and 28 deletions

View File

@ -122,8 +122,6 @@ func mapToResourceEntity(in []ResourceInput, parentSpace types.Space, now int64)
Network: res.Network,
Region: strings.Join(res.Region, " "), // TODO fix
Metadata: res.Metadata,
GatewayHost: res.GatewayHost,
GatewayPort: res.GatewayPort, // No template as of now
Created: now,
Updated: now,
}

View File

@ -47,8 +47,6 @@ const (
ipreso_network,
ipreso_region,
ipreso_opentofu_params,
ipreso_gateway_host,
ipreso_gateway_port,
ipreso_infra_provider_template_id
`
infraProviderResourceSelectColumns = "ipreso_id," + infraProviderResourceInsertColumns
@ -68,8 +66,6 @@ type infraProviderResource struct {
Network null.String `db:"ipreso_network"`
Region string `db:"ipreso_region"` // need list maybe
OpenTofuParams []byte `db:"ipreso_opentofu_params"`
GatewayHost null.String `db:"ipreso_gateway_host"`
GatewayPort null.String `db:"ipreso_gateway_port"`
TemplateID null.Int `db:"ipreso_infra_provider_template_id"`
Created int64 `db:"ipreso_created"`
Updated int64 `db:"ipreso_updated"`
@ -172,8 +168,6 @@ func (s infraProviderResourceStore) Create(
infraProviderResource.Network,
infraProviderResource.Region,
jsonBytes,
infraProviderResource.GatewayHost,
infraProviderResource.GatewayPort,
infraProviderResource.TemplateID,
).
Suffix(ReturningClause + infraProviderResourceIDColumn)
@ -257,8 +251,6 @@ func mapToInfraProviderResource(_ context.Context,
Network: in.Network.Ptr(),
Region: in.Region,
Metadata: openTofuParamsMap,
GatewayHost: in.GatewayHost.Ptr(),
GatewayPort: in.GatewayPort.Ptr(),
TemplateID: in.TemplateID.Ptr(),
Created: in.Created,
Updated: in.Updated,
@ -283,8 +275,6 @@ func (s infraProviderResourceStore) mapToInternalInfraProviderResource(_ context
Network: null.StringFromPtr(in.Network),
Region: in.Region,
OpenTofuParams: jsonBytes,
GatewayHost: null.StringFromPtr(in.GatewayHost),
GatewayPort: null.StringFromPtr(in.GatewayPort),
TemplateID: null.IntFromPtr(in.TemplateID),
Created: in.Created,
Updated: in.Updated,

View File

@ -74,10 +74,11 @@ type infraProvisioned struct {
}
type infraProvisionedGatewayView struct {
GitspaceInstanceIdentifier string `db:"iprov_gitspace_uid"`
SpaceID int64 `db:"iprov_space_id"`
ServerHostIP string `db:"iprov_server_host_ip"`
ServerHostPort string `db:"iprov_server_host_port"`
GitspaceInstanceIdentifier string `db:"iprov_gitspace_uid"`
SpaceID int64 `db:"iprov_space_id"`
ServerHostIP string `db:"iprov_server_host_ip"`
ServerHostPort string `db:"iprov_server_host_port"`
Infrastructure *string `db:"iprov_response_metadata"`
}
func NewInfraProvisionedStore(db *sqlx.DB) store.InfraProvisionedStore {
@ -112,11 +113,14 @@ func (i infraProvisionedStore) FindAllLatestByGateway(
gatewayHost string,
) ([]*types.InfraProvisionedGatewayView, error) {
stmt := database.Builder.
Select("gits_uid as iprov_gitspace_uid, iprov_space_id, iprov_server_host_ip, iprov_server_host_port").
Select(`gits_uid as iprov_gitspace_uid,
iprov_space_id,
iprov_server_host_ip,
iprov_server_host_port,
iprov_response_metadata`).
From(infraProvisionedTable).
Join(fmt.Sprintf("%s ON iprov_infra_provider_resource_id = ipreso_id", infraProviderResourceTable)).
Join(fmt.Sprintf("%s ON iprov_gitspace_id = gits_id", gitspaceInstanceTable)).
Where("ipreso_gateway_host = ?", gatewayHost).
Where("iprov_proxy_host = ?", gatewayHost).
Where("iprov_infra_status = ?", enum.InfraStatusProvisioned).
OrderBy("iprov_created DESC")
@ -140,6 +144,7 @@ func (i infraProvisionedStore) FindAllLatestByGateway(
SpaceID: entity.SpaceID,
ServerHostIP: entity.ServerHostIP,
ServerHostPort: entity.ServerHostPort,
Infrastructure: entity.Infrastructure,
}
}

View File

@ -0,0 +1,2 @@
ALTER TABLE infra_provider_resources ADD COLUMN ipreso_gateway_host TEXT;
ALTER TABLE infra_provider_resources ADD COLUMN ipreso_gateway_port TEXT;

View File

@ -0,0 +1,2 @@
ALTER TABLE infra_provider_resources DROP COLUMN ipreso_gateway_host;
ALTER TABLE infra_provider_resources DROP COLUMN ipreso_gateway_port;

View File

@ -0,0 +1,2 @@
ALTER TABLE infra_provider_resources ADD COLUMN ipreso_gateway_host TEXT;
ALTER TABLE infra_provider_resources ADD COLUMN ipreso_gateway_port TEXT;

View File

@ -0,0 +1,2 @@
ALTER TABLE infra_provider_resources DROP COLUMN ipreso_gateway_host;
ALTER TABLE infra_provider_resources DROP COLUMN ipreso_gateway_port;

View File

@ -43,8 +43,6 @@ type InfraProviderResource struct {
Network *string `json:"network"`
Region string `json:"region"`
Metadata map[string]string `json:"metadata"`
GatewayHost *string `json:"gateway_host"`
GatewayPort *string `json:"gateway_port"`
// Deprecated. Set template identifier in Metadata.
TemplateID *int64 `json:"-"`
// Deprecated. Set template identifier in Metadata.

View File

@ -38,6 +38,7 @@ type InfraProvisionedGatewayView struct {
SpaceID int64
ServerHostIP string
ServerHostPort string
Infrastructure *string
}
type InfraProvisionedUpdateGatewayRequest struct {
@ -46,10 +47,3 @@ type InfraProvisionedUpdateGatewayRequest struct {
GatewayHost string `json:"gateway_host"`
GatewayPort int32 `json:"gateway_port"`
}
type InfraProvisionedResponse struct {
ServerHost string `json:"server_host"`
ServerPort string `json:"server_port"`
GitspaceInstanceIdentifier string `json:"gitspace_id"`
SpaceID int64 `json:"space_id"`
}