Skip to content

chore: migration number fix #5840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions scripts/sql/286_copy_container_image_v2.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
-- update the is_latest flag to true, for the plugin version 1.0.0
UPDATE plugin_metadata
SET is_latest = true
WHERE id = (
SELECT id
FROM plugin_metadata
WHERE name='Copy container image'
AND plugin_version='1.0.0'
AND is_latest = false
AND deleted = false
);

DO
$$
DECLARE
temprow record;
BEGIN
-- select the plugin_metadata_id, plugin_step_id, plugin_pipeline_script_id
SELECT plugin_metadata.id AS plugin_metadata_id,
plugin_step.id AS plugin_step_id,
plugin_step.script_id AS plugin_pipeline_script_id
INTO temprow
FROM plugin_metadata
LEFT JOIN plugin_step ON plugin_metadata.id = plugin_step.plugin_id
WHERE plugin_metadata.plugin_version='2.0.0'
AND plugin_metadata.name='Copy container image';

-- down script for the new plugin version 2.0.0
DELETE FROM plugin_step_variable
WHERE plugin_step_id = temprow.plugin_step_id;
DELETE FROM script_path_arg_port_mapping
WHERE script_id = temprow.plugin_pipeline_script_id;
DELETE FROM plugin_step
WHERE plugin_id = temprow.plugin_metadata_id;
DELETE FROM plugin_stage_mapping
WHERE plugin_id = temprow.plugin_metadata_id;
DELETE FROM pipeline_stage_step_variable
WHERE pipeline_stage_step_id IN (
SELECT id
FROM pipeline_stage_step
WHERE ref_plugin_id = temprow.plugin_metadata_id
);
DELETE FROM pipeline_stage_step
WHERE ref_plugin_id = temprow.plugin_metadata_id;
DELETE from plugin_pipeline_script
WHERE id = temprow.plugin_pipeline_script_id;
DELETE FROM plugin_tag_relation
WHERE plugin_id = temprow.plugin_metadata_id;
DELETE FROM plugin_metadata
WHERE id = temprow.plugin_metadata_id;

END;
$$;
69 changes: 69 additions & 0 deletions scripts/sql/286_copy_container_image_v2.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
INSERT INTO "plugin_parent_metadata" ("id", "name", "identifier", "description", "type", "icon", "deleted", "created_on", "created_by", "updated_on", "updated_by")
SELECT nextval('id_seq_plugin_parent_metadata'), 'Copy container image','copy-container-image', 'Copy container images from the source repository to a desired repository','PRESET','https://raw.githubusercontent.com/devtron-labs/devtron/main/assets/ic-plugin-copy-container-image.png','f', 'now()', 1, 'now()', 1
WHERE NOT EXISTS (
SELECT 1
FROM plugin_parent_metadata
WHERE identifier='copy-container-image'
AND deleted = false
);

-- update the plugin_metadata with the plugin_parent_metadata_id
UPDATE plugin_metadata
SET plugin_parent_metadata_id = (
SELECT id
FROM plugin_parent_metadata
WHERE identifier='copy-container-image'
AND deleted = false
),plugin_version='1.0.0'
WHERE name='Copy container image'
AND (
plugin_parent_metadata_id IS NULL
OR plugin_parent_metadata_id = 0
)
AND deleted = false;


UPDATE plugin_metadata SET is_latest = false WHERE id = (SELECT id FROM plugin_metadata WHERE name= 'Copy container image' and is_latest= true);


INSERT INTO "plugin_metadata" ("id", "name", "description","deleted", "created_on", "created_by", "updated_on", "updated_by","plugin_parent_metadata_id","plugin_version","is_deprecated","is_latest")
VALUES (nextval('id_seq_plugin_metadata'), 'Copy container image','Copy container images from the source repository to a desired repository','f', 'now()', 1, 'now()', 1, (SELECT id FROM plugin_parent_metadata WHERE identifier='copy-container-image'),'2.0.0', false, true);


INSERT INTO "plugin_tag_relation" ("id", "tag_id", "plugin_id", "created_on", "created_by", "updated_on", "updated_by")
VALUES (nextval('id_seq_plugin_tag_relation'),(SELECT id FROM plugin_tag WHERE name='Image source') , (SELECT id FROM plugin_metadata WHERE name='Copy container image' and plugin_version='1.0.0'),'now()', 1, 'now()', 1);


INSERT INTO "plugin_stage_mapping" ("plugin_id","stage_type","created_on", "created_by", "updated_on", "updated_by")
VALUES ((SELECT id FROM plugin_metadata WHERE plugin_version='2.0.0' and name='Copy container image' and deleted= false),0,'now()', 1, 'now()', 1);


INSERT INTO "plugin_pipeline_script" ("id","type","mount_directory_from_host","container_image_path","deleted","created_on", "created_by", "updated_on", "updated_by")
VALUES (nextval('id_seq_plugin_pipeline_script'),'CONTAINER_IMAGE','t','quay.io/devtron/devtron-plugins:skopeo-2.0.1','f','now()',1,'now()',1);

INSERT INTO "script_path_arg_port_mapping" ("id", "type_of_mapping", "file_path_on_disk","file_path_on_container","script_id","deleted","created_on","created_by", "updated_on", "updated_by")
VALUES (nextval('id_seq_script_path_arg_port_mapping'),'FILE_PATH','/tmp/pluginArtifacts' ,'/tmp/output',(SELECT last_value FROM id_seq_plugin_pipeline_script),'f','now()', 1, 'now()', 1);

INSERT INTO "plugin_step" ("id", "plugin_id","name","description","index","step_type","script_id","deleted", "created_on", "created_by", "updated_on", "updated_by")
VALUES (nextval('id_seq_plugin_step'),(SELECT id FROM plugin_metadata WHERE plugin_version='2.0.0' and name='Copy container image' and deleted= false),'Step 1','Step 1 - Copy container images','1','INLINE',(SELECT last_value FROM id_seq_plugin_pipeline_script),'f','now()', 1, 'now()', 1);

INSERT INTO "plugin_step_variable" ("id", "plugin_step_id", "name", "format", "description", "is_exposed", "allow_empty_value","variable_type", "value_type", "variable_step_index", "deleted", "created_on", "created_by", "updated_on", "updated_by")
VALUES (nextval('id_seq_plugin_step_variable'), (SELECT ps.id FROM plugin_metadata p inner JOIN plugin_step ps on ps.plugin_id=p.id WHERE p.name='Copy container image' and p.plugin_version='2.0.0' and ps."index"=1 and ps.deleted=false), 'DESTINATION_INFO','STRING',
'In case of CI, build image will be copied to registry and repository provided in DESTINATION_INFO. In case of PRE-CD/POST-CD, Image used to trigger stage will be copied in DESTINATION_INFO
Format:
<registry1> | <repo1>,<repo2>', true,false,'INPUT','NEW',1 ,'f','now()', 1, 'now()', 1);

INSERT INTO "plugin_step_variable" ("id", "plugin_step_id", "name", "format", "description", "is_exposed", "allow_empty_value","variable_type", "value_type", "variable_step_index",reference_variable_name, "deleted", "created_on", "created_by", "updated_on", "updated_by")
VALUES (nextval('id_seq_plugin_step_variable'), (SELECT ps.id FROM plugin_metadata p inner JOIN plugin_step ps on ps.plugin_id=p.id WHERE p.name='Copy container image' and p.plugin_version='2.0.0' and ps."index"=1 and ps.deleted=false), 'DOCKER_IMAGE','STRING','',false,true,'INPUT','GLOBAL',1 ,'DOCKER_IMAGE','f','now()', 1, 'now()', 1);

INSERT INTO "plugin_step_variable" ("id", "plugin_step_id", "name", "format", "description", "is_exposed", "allow_empty_value","variable_type", "value_type", "variable_step_index",reference_variable_name, "deleted", "created_on", "created_by", "updated_on", "updated_by")
VALUES (nextval('id_seq_plugin_step_variable'), (SELECT ps.id FROM plugin_metadata p inner JOIN plugin_step ps on ps.plugin_id=p.id WHERE p.name='Copy container image' and p.plugin_version='2.0.0' and ps."index"=1 and ps.deleted=false), 'REGISTRY_DESTINATION_IMAGE_MAP','STRING','map of registry name and images needed to be copied in that images',false,true,'INPUT','GLOBAL',1 ,'REGISTRY_DESTINATION_IMAGE_MAP','f','now()', 1, 'now()', 1);

INSERT INTO "plugin_step_variable" ("id", "plugin_step_id", "name", "format", "description", "is_exposed", "allow_empty_value","variable_type", "value_type", "variable_step_index",reference_variable_name, "deleted", "created_on", "created_by", "updated_on", "updated_by")
VALUES (nextval('id_seq_plugin_step_variable'), (SELECT ps.id FROM plugin_metadata p inner JOIN plugin_step ps on ps.plugin_id=p.id WHERE p.name='Copy container image' and p.plugin_version='2.0.0' and ps."index"=1 and ps.deleted=false), 'REGISTRY_CREDENTIALS','STRING','',false,true,'INPUT','GLOBAL',1 ,'REGISTRY_CREDENTIALS','f','now()', 1, 'now()', 1);

INSERT INTO "plugin_step_variable" ("id", "plugin_step_id", "name", "format", "description", "is_exposed", "allow_empty_value","variable_type", "value_type", "variable_step_index",reference_variable_name, "deleted", "created_on", "created_by", "updated_on", "updated_by")
VALUES (nextval('id_seq_plugin_step_variable'), (SELECT ps.id FROM plugin_metadata p inner JOIN plugin_step ps on ps.plugin_id=p.id WHERE p.name='Copy container image' and p.plugin_version='2.0.0' and ps."index"=1 and ps.deleted=false), 'DOCKER_IMAGE_TAG','STRING','',false,true,'INPUT','GLOBAL',1 ,'DOCKER_TAG','f','now()', 1, 'now()', 1);

INSERT INTO "plugin_step_variable" ("id", "plugin_step_id", "name", "format", "description", "is_exposed", "allow_empty_value","variable_type", "value_type", "variable_step_index",reference_variable_name, "deleted", "created_on", "created_by", "updated_on", "updated_by")
VALUES (nextval('id_seq_plugin_step_variable'), (SELECT ps.id FROM plugin_metadata p inner JOIN plugin_step ps on ps.plugin_id=p.id WHERE p.name='Copy container image' and p.plugin_version='2.0.0' and ps."index"=1 and ps.deleted=false), 'DOCKER_IMAGE_TAG_OVERRIDE','STRING','',true,true,'INPUT','FROM_PREVIOUS_STEP',1 ,'DOCKER_IMAGE_TAG_OVERRIDE','f','now()', 1, 'now()', 1);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--empty script for maintaining script number common across repo.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--empty script for maintaining script number common across repo.
Loading