Current Behavior
The project currently manages database schema changes manually despite having multiple interconnected models such as User, ShelfItem, and ReadingStats. Any modification to the schema (e.g., adding fields, changing types, or relationships) requires direct database updates without version control.
This leads to:
High risk of data inconsistency or loss
Difficulties in maintaining parity between development and production environments
No rollback mechanism for failed schema changes
Increased chances of deployment errors
Suggested Improvement
Introduce a database migration system (e.g., Alembic or Flask-Migrate) to handle schema evolution in a structured and version-controlled manner.
The system should:
Track schema changes through migration scripts
Allow safe upgrades and downgrades of database versions
Integrate with the existing ORM models
Ensure consistent schema across all environments
This will replace manual schema updates with a reliable and automated workflow.
Benefits
Prevents data loss and schema inconsistencies
Enables safe and reversible database changes
Improves deployment reliability and team collaboration
Aligns the project with industry-standard practices
Possible Implementation
Integrate Flask-Migrate (Alembic) into the project
Initialize migration environment and configuration
Generate migration scripts from existing models
Apply migrations to synchronize database schema
Update deployment workflow to include migration steps
Current Behavior
The project currently manages database schema changes manually despite having multiple interconnected models such as User, ShelfItem, and ReadingStats. Any modification to the schema (e.g., adding fields, changing types, or relationships) requires direct database updates without version control.
This leads to:
High risk of data inconsistency or loss
Difficulties in maintaining parity between development and production environments
No rollback mechanism for failed schema changes
Increased chances of deployment errors
Suggested Improvement
Introduce a database migration system (e.g., Alembic or Flask-Migrate) to handle schema evolution in a structured and version-controlled manner.
The system should:
Track schema changes through migration scripts
Allow safe upgrades and downgrades of database versions
Integrate with the existing ORM models
Ensure consistent schema across all environments
This will replace manual schema updates with a reliable and automated workflow.
Benefits
Prevents data loss and schema inconsistencies
Enables safe and reversible database changes
Improves deployment reliability and team collaboration
Aligns the project with industry-standard practices
Possible Implementation
Integrate Flask-Migrate (Alembic) into the project
Initialize migration environment and configuration
Generate migration scripts from existing models
Apply migrations to synchronize database schema
Update deployment workflow to include migration steps