fix: Handle partially migrated databases in migration 002 detection
CRITICAL HOTFIX for production deployment failure Problem: - Production database had migration 001 applied but not migration 002 - Migration 002's tables (tokens, authorization_codes) already existed from SCHEMA_SQL - Smart detection only checked when migration_count == 0 (fresh database) - For partially migrated databases (count > 0), tried to run full migration - This failed with "table already exists" error Solution: - Always check migration 002's state, regardless of migration_count - If tables exist with correct structure, skip table creation - Create missing indexes only - Mark migration as applied Testing: - Manual verification with production scenario: SUCCESS - 561 automated tests passing - test_run_migrations_partial_applied confirms fix works Impact: - Fixes deployment on partially migrated production databases - No impact on fresh or fully migrated databases - Backwards compatible with all database states Version: 1.0.0-rc.2 → 1.0.0-rc.3 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
21
CHANGELOG.md
21
CHANGELOG.md
@@ -7,6 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [1.0.0-rc.3] - 2025-11-24
|
||||
|
||||
### Fixed
|
||||
- **CRITICAL: Migration detection failure for partially migrated databases**: Fixed migration 002 detection logic
|
||||
- Production database had migration 001 applied but not migration 002
|
||||
- Migration 002's tables (tokens, authorization_codes) already existed from SCHEMA_SQL in v1.0.0-rc.1
|
||||
- Previous logic only used smart detection for fresh databases (migration_count == 0)
|
||||
- For partially migrated databases (migration_count > 0), it tried to run migration 002 normally
|
||||
- This caused "table already exists" error because CREATE TABLE statements would fail
|
||||
- Fixed by checking migration 002's state regardless of migration_count
|
||||
- Migration 002 now checks if its tables exist before running, skips table creation if they do
|
||||
- Missing indexes are created even when tables exist, ensuring complete database state
|
||||
- Fixes deployment failure on production database with existing tables but missing migration record
|
||||
|
||||
### Technical Details
|
||||
- Affected databases: Any database with migration 001 applied but not migration 002, where tables were created by SCHEMA_SQL
|
||||
- Root cause: Smart detection (is_migration_needed) was only called when migration_count == 0
|
||||
- Solution: Always check migration 002's state, regardless of migration_count
|
||||
- Backwards compatibility: Works for fresh databases, partially migrated databases, and fully migrated databases
|
||||
- Migration 002 will create only missing indexes if tables already exist
|
||||
|
||||
## [1.0.0-rc.2] - 2025-11-24
|
||||
|
||||
### Fixed
|
||||
|
||||
Reference in New Issue
Block a user