Skip to content

Commit eb01a55

Browse files
committed
feat: always log specific servers being modified in migration 008
- Log all servers being deleted with their name, version, and reason - Log all servers having status updated with current status - Provides full transparency for audit purposes - Still includes safety checks to prevent unexpected data loss
1 parent 419362f commit eb01a55

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

internal/database/migrations/008_clean_invalid_data.sql

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,10 @@ BEGIN
6565
RAISE NOTICE ' Servers to UPDATE (fix status): %', invalid_status_count;
6666
RAISE NOTICE ' Duplicate name+version pairs: %', duplicate_count;
6767

68-
-- SAFETY CHECK: Fail if numbers don't match what we found in production
69-
-- Based on comprehensive analysis of production data (2025-09-30), we expect:
70-
-- - 5 servers to delete (1 invalid name + 4 empty versions)
71-
-- - 1 server status to update
72-
IF total_to_delete != 5 THEN
73-
-- Log the specific servers that would be deleted
74-
RAISE NOTICE 'Servers that would be deleted:';
68+
-- Always log the specific servers that will be deleted for transparency
69+
IF total_to_delete > 0 THEN
70+
RAISE NOTICE '';
71+
RAISE NOTICE 'Servers that will be deleted:';
7572
FOR r IN
7673
SELECT value->>'name' as name, value->>'version' as version,
7774
CASE
@@ -87,13 +84,12 @@ BEGIN
8784
LOOP
8885
RAISE NOTICE ' - % @ % (reason: %)', r.name, COALESCE(r.version, '<NULL>'), r.reason;
8986
END LOOP;
90-
91-
RAISE EXCEPTION 'Safety check failed: Expected to delete exactly 5 servers but would delete %. Check the log above for details. Aborting to prevent data loss.', total_to_delete;
9287
END IF;
9388

94-
IF invalid_status_count != 1 THEN
95-
-- Log the specific servers that would have status updated
96-
RAISE NOTICE 'Servers that would have status updated:';
89+
-- Always log the specific servers that will have status updated for transparency
90+
IF invalid_status_count > 0 THEN
91+
RAISE NOTICE '';
92+
RAISE NOTICE 'Servers that will have status updated:';
9793
FOR r IN
9894
SELECT value->>'name' as name, value->>'version' as version, value->>'status' as status
9995
FROM servers
@@ -104,7 +100,17 @@ BEGIN
104100
LOOP
105101
RAISE NOTICE ' - % @ % (current status: %)', r.name, r.version, r.status;
106102
END LOOP;
103+
END IF;
107104

105+
-- SAFETY CHECK: Fail if numbers don't match what we found in production
106+
-- Based on comprehensive analysis of production data (2025-09-30), we expect:
107+
-- - 5 servers to delete (1 invalid name + 4 empty versions)
108+
-- - 1 server status to update
109+
IF total_to_delete != 5 THEN
110+
RAISE EXCEPTION 'Safety check failed: Expected to delete exactly 5 servers but would delete %. Check the log above for details. Aborting to prevent data loss.', total_to_delete;
111+
END IF;
112+
113+
IF invalid_status_count != 1 THEN
108114
RAISE EXCEPTION 'Safety check failed: Expected to update exactly 1 server status but would update %. Check the log above for details. Aborting to prevent data corruption.', invalid_status_count;
109115
END IF;
110116
END $$;

0 commit comments

Comments
 (0)