diff --git a/internal/sql/repository/pipelineConfig/PipelineRepository.go b/internal/sql/repository/pipelineConfig/PipelineRepository.go index 3976d20e4c..ebbbe2cf6b 100644 --- a/internal/sql/repository/pipelineConfig/PipelineRepository.go +++ b/internal/sql/repository/pipelineConfig/PipelineRepository.go @@ -145,6 +145,7 @@ type PipelineRepository interface { FindDeploymentAppTypeByIds(ids []int) (pipelines []*Pipeline, err error) GetAllAppsByClusterAndDeploymentAppType(clusterIds []int, deploymentAppName string) ([]*PipelineDeploymentConfigObj, error) GetAllArgoAppInfoByDeploymentAppNames(deploymentAppNames []string) ([]*PipelineDeploymentConfigObj, error) + FindEnvIdsByIdsInIncludingDeleted(ids []int) ([]int, error) } type CiArtifactDTO struct { @@ -951,3 +952,18 @@ func (impl *PipelineRepositoryImpl) GetAllArgoAppInfoByDeploymentAppNames(deploy Select(&result) return result, err } + +func (impl *PipelineRepositoryImpl) FindEnvIdsByIdsInIncludingDeleted(ids []int) ([]int, error) { + var envIds []int + if len(ids) == 0 { + return envIds, nil + } + err := impl.dbConnection.Model(&Pipeline{}). + Column("pipeline.environment_id"). + Where("pipeline.id in (?)", pg.In(ids)). + Select(&envIds) + if err != nil { + impl.logger.Errorw("error on fetching pipelines", "ids", ids, "err", err) + } + return envIds, err +} diff --git a/scripts/sql/33203600_target_installations.down.sql b/scripts/sql/33203600_target_installations.down.sql new file mode 100644 index 0000000000..944ab40e5a --- /dev/null +++ b/scripts/sql/33203600_target_installations.down.sql @@ -0,0 +1,241 @@ +BEGIN; + +DELETE FROM global_policy where policy_of = 'RELEASE_ACTION_CHECK' AND version = 'V2'; +-- reverting to old state +DROP INDEX IF EXISTS idx_unique_policy_name_policy_of_version; +-- reverting to old state +CREATE UNIQUE INDEX idx_unique_policy_name_policy_of + ON global_policy (name,policy_of) + WHERE deleted = false; + +UPDATE devtron_resource_schema set schema = '{ + "type": "object", + "title": "Release Schema", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "required": + [ + "version", + "kind", + "overview", + "status" + ], + "properties": + { + "kind": + { + "const": "release" + }, + "status": + { + "type": "object", + "required": + [ + "config" + ], + "properties": + { + "config": + { + "type": "object", + "required": + [ + "status" + ], + "properties": + { + "lock": + { + "type": "boolean" + }, + "status": + { + "enum": + [ + "draft", + "readyForRelease", + "hold" + ], + "type": "string" + } + } + } + } + }, + "version": + { + "enum": + [ + "alpha1" + ], + "type": "string" + }, + "overview": + { + "type": "object", + "required": + [ + "id", + "releaseVersion" + ], + "properties": + { + "id": + { + "type": "number" + }, + "icon": + { + "type": "string", + "contentEncoding": "base64" + }, + "name": + { + "type": "string" + }, + "note": + { + "type": "string" + }, + "tags": + { + "additionalProperties": + { + "type": "string" + } + }, + "idType": + { + "enum": + [ + "resourceObjectId", + "oldObjectId" + ], + "type": "string", + "description": "for existing resources in the system we keep original ids of their tables in id field. Like id of apps table is kept for devtron applications. But in release we keep data as devtron resource only. To differ between nature of these two types of id values." + }, + "metadata": + { + "type": "object", + "required": + [ + "Type of release", + "Release Managers", + "On-Duty" + ], + "properties": + { + "On-Duty": + { + "type": "array", + "items": + { + "type": "object", + "refType": "#/references/users" + }, + "minItems": 1, + "uniqueItems": true + }, + "Milestones": + { + "type": "object", + "properties": + { + "Release end date": + { + "type": "string", + "format": "date" + }, + "30% milestone date": + { + "type": "string", + "format": "date" + }, + "70% milestone date": + { + "type": "string", + "format": "date" + }, + "Release planned start date": + { + "type": "string", + "format": "date" + } + } + }, + "Type of release": + { + "enum": + [ + "Major", + "Minor", + "Patch" + ], + "type": "string" + }, + "Release Managers": + { + "type": "array", + "items": + { + "type": "object", + "refType": "#/references/users" + }, + "minItems": 1, + "uniqueItems": true + }, + "Target customers": + { + "type": "array", + "items": + { + "type": "string" + }, + "uniqueItems": true + }, + "Released customers": + { + "type": "array", + "items": + { + "type": "string" + }, + "uniqueItems": true + } + } + }, + "createdBy": + { + "type": "object", + "refType": "#/references/users" + }, + "createdOn": + { + "type": "string" + }, + "description": + { + "type": "string" + }, + "releaseVersion": + { + "type": "string" + }, + "firstReleasedOn": + { + "type": "string", + "format": "date-time" + } + } + }, + "taskMapping": + { + "type": "array" + }, + "dependencies": + { + "type": "array" + } + } +}' where devtron_resource_id=(select id from devtron_resource where kind = 'release'); + +COMMIT; \ No newline at end of file diff --git a/scripts/sql/33203600_target_installations.up.sql b/scripts/sql/33203600_target_installations.up.sql new file mode 100644 index 0000000000..ac3c8b93b9 --- /dev/null +++ b/scripts/sql/33203600_target_installations.up.sql @@ -0,0 +1,492 @@ +BEGIN; + +-- Drop the existing index if it exists because it did not have the version to it, added new index with version +DROP INDEX IF EXISTS idx_unique_policy_name_policy_of; +-- Create unique index for global_policy table +CREATE UNIQUE INDEX idx_unique_policy_name_policy_of_version + ON global_policy (name,policy_of,version) + WHERE deleted = false; + +INSERT INTO global_policy(name, policy_of, version, description, policy_json, enabled, deleted, created_by, created_on, updated_by, updated_on) +VALUES('ReleaseActionCheckPolicy', 'RELEASE_ACTION_CHECK', 'V2', 'Policy used for validating different actions requested on release.', + '{ + "definitions": + [ + { + "operationType": "patch", + "operationPaths": + [ + "overview.description", + "overview.releaseNote", + "overview.tags", + "overview.name", + "overview.metadata", + "status.config.lock", + "status.config" + ], + "possibleFromStates": + [ + { + "configStatus": "draft", + "dependencyArtifactStatus": "*", + "rolloutStatus": "*", + "lockStatus": "*", + "isReleaseTrackAppPropagationOffending": "*", + "areAllReleasedTargetPresent": "*" + }, + { + "configStatus": "readyForRelease", + "dependencyArtifactStatus": "*", + "rolloutStatus": "*", + "lockStatus": "*", + "isReleaseTrackAppPropagationOffending": "*", + "areAllReleasedTargetPresent": "*" + }, + { + "configStatus": "hold", + "dependencyArtifactStatus": "*", + "rolloutStatus": "*", + "lockStatus": "*", + "isReleaseTrackAppPropagationOffending": "*", + "areAllReleasedTargetPresent": "*" + } + ] + }, + { + "operationType": "patch", + "operationPaths": + [ + "target" + ], + "stateTo": + { + "configStatus": "*", + "dependencyArtifactStatus": "*", + "rolloutStatus": "*", + "lockStatus": "*", + "isReleaseTrackAppPropagationOffending": "*", + "areAllReleasedTargetPresent": "yes" + }, + "possibleFromStates": + [ + { + "configStatus": "draft", + "dependencyArtifactStatus": "*", + "rolloutStatus": "*", + "lockStatus": "*", + "isReleaseTrackAppPropagationOffending": "*", + "areAllReleasedTargetPresent": "*" + }, + { + "configStatus": "readyForRelease", + "dependencyArtifactStatus": "*", + "rolloutStatus": "*", + "lockStatus": "*", + "isReleaseTrackAppPropagationOffending": "*", + "areAllReleasedTargetPresent": "*" + }, + { + "configStatus": "hold", + "dependencyArtifactStatus": "*", + "rolloutStatus": "*", + "lockStatus": "*", + "isReleaseTrackAppPropagationOffending": "*", + "areAllReleasedTargetPresent": "*" + } + ] + }, + { + "operationType": "patch", + "operationPaths": + [ + "dependency.applications" + ], + "stateTo": + { + "configStatus": "draft", + "dependencyArtifactStatus": "*", + "rolloutStatus": "notDeployed", + "lockStatus": "unLocked", + "isReleaseTrackAppPropagationOffending": "yes", + "areAllReleasedTargetPresent": "*" + }, + "possibleFromStates": + [ + { + "configStatus": "draft", + "dependencyArtifactStatus": "*", + "rolloutStatus": "notDeployed", + "lockStatus": "unLocked", + "isReleaseTrackAppPropagationOffending": "*", + "areAllReleasedTargetPresent": "*" + } + ] + }, + { + "operationType": "patch", + "operationPaths": + [ + "dependency.applications.image" + ], + "possibleFromStates": + [ + { + "configStatus": "draft", + "dependencyArtifactStatus": "*", + "rolloutStatus": "notDeployed", + "lockStatus": "unLocked", + "isReleaseTrackAppPropagationOffending": "*", + "areAllReleasedTargetPresent": "*" + } + ] + }, + { + "operationType": "patch", + "operationPaths": + [ + "dependency.applications.instruction" + ], + "possibleFromStates": + [ + { + "configStatus": "draft", + "dependencyArtifactStatus": "*", + "rolloutStatus": "notDeployed", + "lockStatus": "unLocked", + "isReleaseTrackAppPropagationOffending": "*", + "areAllReleasedTargetPresent": "*" + }, + { + "configStatus": "readyForRelease", + "dependencyArtifactStatus": "*", + "rolloutStatus": "notDeployed", + "lockStatus": "unLocked", + "isReleaseTrackAppPropagationOffending": "*", + "areAllReleasedTargetPresent": "*" + }, + { + "configStatus": "hold", + "dependencyArtifactStatus": "*", + "rolloutStatus": "notDeployed", + "lockStatus": "unLocked", + "isReleaseTrackAppPropagationOffending": "*", + "areAllReleasedTargetPresent": "*" + } + ] + }, + { + "operationType": "deploymentTrigger", + "possibleFromStates": + [ + { + "configStatus": "readyForRelease", + "dependencyArtifactStatus": "*", + "rolloutStatus": "*", + "lockStatus": "locked", + "isReleaseTrackAppPropagationOffending": "yes", + "areAllReleasedTargetPresent": "yes" + + }, + { + "configStatus": "readyForRelease", + "dependencyArtifactStatus": "*", + "rolloutStatus": "partiallyDeployed", + "lockStatus": "locked", + "isReleaseTrackAppPropagationOffending": "*", + "areAllReleasedTargetPresent": "yes" + }, + { + "configStatus": "readyForRelease", + "dependencyArtifactStatus": "*", + "rolloutStatus": "completelyDeployed", + "lockStatus": "locked", + "isReleaseTrackAppPropagationOffending": "*", + "areAllReleasedTargetPresent": "yes" + } + ] + }, + { + "operationType": "delete", + "possibleFromStates": + [ + { + "configStatus": "draft", + "dependencyArtifactStatus": "*", + "rolloutStatus": "notDeployed", + "lockStatus": "*", + "isReleaseTrackAppPropagationOffending": "*", + "areAllReleasedTargetPresent": "*" + }, + { + "configStatus": "readyForRelease", + "dependencyArtifactStatus": "*", + "rolloutStatus": "notDeployed", + "lockStatus": "*", + "isReleaseTrackAppPropagationOffending": "*", + "areAllReleasedTargetPresent": "*" + }, + { + "configStatus": "hold", + "dependencyArtifactStatus": "*", + "rolloutStatus": "notDeployed", + "lockStatus": "*", + "isReleaseTrackAppPropagationOffending": "*", + "areAllReleasedTargetPresent": "*" + }, + { + "configStatus": "rescind", + "dependencyArtifactStatus": "*", + "rolloutStatus": "*", + "lockStatus": "*", + "isReleaseTrackAppPropagationOffending": "*", + "areAllReleasedTargetPresent": "*" + }, + { + "configStatus": "corrupted", + "dependencyArtifactStatus": "*", + "rolloutStatus": "*", + "lockStatus": "*", + "isReleaseTrackAppPropagationOffending": "*", + "areAllReleasedTargetPresent": "*" + } + ] + } + ], + "consequence": "BLOCK" +}', true, false, 1, now(),1,now()); + +UPDATE devtron_resource_schema set schema = '{ + "type": "object", + "title": "Release Schema", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "required": + [ + "version", + "kind", + "overview", + "status" + ], + "properties": + { + "kind": + { + "const": "release" + }, + "status": + { + "type": "object", + "required": + [ + "config" + ], + "properties": + { + "config": + { + "type": "object", + "required": + [ + "status" + ], + "properties": + { + "lock": + { + "type": "boolean" + }, + "status": + { + "enum": + [ + "draft", + "readyForRelease", + "hold" + ], + "type": "string" + } + } + } + } + }, + "version": + { + "enum": + [ + "alpha1" + ], + "type": "string" + }, + "overview": + { + "type": "object", + "required": + [ + "id", + "releaseVersion" + ], + "properties": + { + "id": + { + "type": "number" + }, + "icon": + { + "type": "string", + "contentEncoding": "base64" + }, + "name": + { + "type": "string" + }, + "note": + { + "type": "string" + }, + "tags": + { + "additionalProperties": + { + "type": "string" + } + }, + "idType": + { + "enum": + [ + "resourceObjectId", + "oldObjectId" + ], + "type": "string", + "description": "for existing resources in the system we keep original ids of their tables in id field. Like id of apps table is kept for devtron applications. But in release we keep data as devtron resource only. To differ between nature of these two types of id values." + }, + "metadata": + { + "type": "object", + "required": + [ + "Type of release", + "Release Managers", + "On-Duty" + ], + "properties": + { + "On-Duty": + { + "type": "array", + "items": + { + "type": "object", + "refType": "#/references/users" + }, + "minItems": 1, + "uniqueItems": true + }, + "Milestones": + { + "type": "object", + "properties": + { + "Release end date": + { + "type": "string", + "format": "date" + }, + "30% milestone date": + { + "type": "string", + "format": "date" + }, + "70% milestone date": + { + "type": "string", + "format": "date" + }, + "Release planned start date": + { + "type": "string", + "format": "date" + } + } + }, + "Type of release": + { + "enum": + [ + "Major", + "Minor", + "Patch" + ], + "type": "string" + }, + "Release Managers": + { + "type": "array", + "items": + { + "type": "object", + "refType": "#/references/users" + }, + "minItems": 1, + "uniqueItems": true + }, + "Target customers": + { + "type": "array", + "items": + { + "type": "string" + }, + "uniqueItems": true + }, + "Released customers": + { + "type": "array", + "items": + { + "type": "string" + }, + "uniqueItems": true + } + } + }, + "createdBy": + { + "type": "object", + "refType": "#/references/users" + }, + "createdOn": + { + "type": "string" + }, + "description": + { + "type": "string" + }, + "releaseVersion": + { + "type": "string" + }, + "firstReleasedOn": + { + "type": "string", + "format": "date-time" + } + } + }, + "taskMapping": + { + "type": "array" + }, + "dependencies": + { + "type": "array" + }, + "target": + { + "type": "object" + } + } +}' where devtron_resource_id=(select id from devtron_resource where kind = 'release'); + +COMMIT; \ No newline at end of file