From 7b0d423beeb5e4419ab8b75ce9c69aa541426ba9 Mon Sep 17 00:00:00 2001 From: Mondo Diaz Date: Tue, 3 Feb 2026 17:22:40 -0600 Subject: [PATCH] Add inline migration for tag removal (024_remove_tags) Adds the tag removal migration to the inline migrations in database.py: - Drops tag-related triggers and functions - Removes tag_constraint column from artifact_dependencies - Makes version_constraint NOT NULL - Drops tags and tag_history tables - Renames uploads.tag_name to version --- backend/app/database.py | 56 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/backend/app/database.py b/backend/app/database.py index ec7edbf..eb938b2 100644 --- a/backend/app/database.py +++ b/backend/app/database.py @@ -538,6 +538,62 @@ def _run_migrations(): WHERE name IN ('npm-public', 'pypi-public', 'maven-central', 'docker-hub'); """, ), + Migration( + name="024_remove_tags", + sql=""" + -- Remove tag system, keeping only versions for artifact references + DO $$ + BEGIN + -- Drop triggers on tags table (if they exist) + DROP TRIGGER IF EXISTS tags_ref_count_insert_trigger ON tags; + DROP TRIGGER IF EXISTS tags_ref_count_delete_trigger ON tags; + DROP TRIGGER IF EXISTS tags_ref_count_update_trigger ON tags; + DROP TRIGGER IF EXISTS tags_updated_at_trigger ON tags; + DROP TRIGGER IF EXISTS tag_changes_trigger ON tags; + + -- Drop the tag change tracking function + DROP FUNCTION IF EXISTS track_tag_changes(); + + -- Remove tag_constraint from artifact_dependencies + IF EXISTS ( + SELECT 1 FROM information_schema.table_constraints + WHERE constraint_name = 'check_constraint_type' + AND table_name = 'artifact_dependencies' + ) THEN + ALTER TABLE artifact_dependencies DROP CONSTRAINT check_constraint_type; + END IF; + + -- Remove the tag_constraint column if it exists + IF EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_name = 'artifact_dependencies' AND column_name = 'tag_constraint' + ) THEN + ALTER TABLE artifact_dependencies DROP COLUMN tag_constraint; + END IF; + + -- Make version_constraint NOT NULL + UPDATE artifact_dependencies SET version_constraint = '*' WHERE version_constraint IS NULL; + ALTER TABLE artifact_dependencies ALTER COLUMN version_constraint SET NOT NULL; + + -- Drop tag_history table first (depends on tags) + DROP TABLE IF EXISTS tag_history; + + -- Drop tags table + DROP TABLE IF EXISTS tags; + + -- Rename uploads.tag_name to version if it exists and version doesn't + IF EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_name = 'uploads' AND column_name = 'tag_name' + ) AND NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_name = 'uploads' AND column_name = 'version' + ) THEN + ALTER TABLE uploads RENAME COLUMN tag_name TO version; + END IF; + END $$; + """, + ), ] with engine.connect() as conn: