-- First ensure all tags have been migrated DO $$ BEGIN -- Check if there are any posts with non-empty tags IF EXISTS ( SELECT 1 FROM posts WHERE tags IS NOT NULL AND array_length(tags, 1) > 0 ) THEN RAISE EXCEPTION 'There are still posts with tags that have not been migrated to categories'; END IF; -- If we get here, it's safe to remove the tags column ALTER TABLE posts DROP COLUMN IF EXISTS tags; END $$;