registry/internal/database/migrations
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Tadas Antanavicius 2d49e5b68c
fix: prevent NULL status values during migration 008 (#587)
## Summary
- Fixes migration 008 failing with "column contains null values" error
- Adds COALESCE protection to handle 126 servers without status fields
- Includes test utilities to reproduce and verify fixes with production
data

## Problem

Migration 008 was failing in production because:
- 126 out of 781 servers have no `status` field in their JSON
- When extracting `rec.value->>'status'`, these became NULL values
- The `ALTER TABLE servers ALTER COLUMN status SET NOT NULL` constraint
then failed

## Solution

1. **Prevent NULLs during migration**: Use COALESCE to provide 'active'
default when status is NULL/empty
2. **Enhanced debugging**: Added RAISE NOTICE statements to log
problematic values
3. **Safety check**: Double-check that throws exception if any NULLs
remain
4. **Test utilities**: Created mirror_data tools to test migrations with
real production data

## Testing

Created and used `scripts/mirror_data/` tools to:
- Fetch all 781 servers from production API
- Load them into a test database
- Verify the migration fix works correctly

### Results:
- **Before fix**: 126 NULL status values created during migration
- **After fix**: 0 NULL status values, all servers have valid status
- Migration completes successfully with NOT NULL constraint

## Test plan
- [x] Tested locally with production data using mirror_data tools
- [x] Verified 0 NULL values after migration (vs 126 before)
- [x] Confirmed NOT NULL constraint adds successfully
- [ ] Deploy to staging and verify migration succeeds
- [ ] Monitor production deployment

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <noreply@anthropic.com>
2025-09-30 06:43:26 -07:00
..
001_initial_schema.sql Refactor database implementation to use PostgreSQL instead of MongoDB (#289) 2025-08-22 01:40:28 +01:00
002_add_server_extensions.sql Allow for vendor extensions on servers (#298) 2025-08-23 09:59:03 +01:00
003_simplify_to_key_value.sql Implement flattened _meta format for server extensions (#331) 2025-09-01 19:27:23 +01:00
004_update_meta_field_format.sql Fix _meta field format for MCP spec compliance (#367) 2025-09-08 11:40:04 -07:00
005_add_server_id_rename_version_id.sql Introduce serverId, rename id to versionId (#465) 2025-09-21 15:00:09 +03:00
006_migrate_server_json_camelcase.sql add migraiton file to convert snake case to camel case (#522) 2025-09-21 15:26:15 +03:00
007_add_publish_constraints.sql Fix race conditions in concurrent server publishing (#528) 2025-09-22 12:16:05 +01:00
008_separate_official_metadata.sql fix: prevent NULL status values during migration 008 (#587) 2025-09-30 06:43:26 -07:00