Skip to content

Add database migration via Alembic for the added errorMessage - #137

Draft
mberz wants to merge 5 commits into
devfrom
enh/db_migration_error_message
Draft

Add database migration via Alembic for the added errorMessage#137
mberz wants to merge 5 commits into
devfrom
enh/db_migration_error_message

Conversation

@mberz

@mberz mberz commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

This pull request introduces Alembic-based database migrations to the project, providing a robust and standardized way to manage schema changes. It adds an initial schema baseline migration, a migration to add the errorMessage (#107 ) field to simulations and simulation runs, and all required Alembic configuration and environment files. The entrypoint script is also updated to automatically apply migrations on startup, ensuring the database schema is always up-to-date.

Database migration framework integration:

  • Added Alembic migration support with configuration files (auto generated: alembic.ini, env.py, script.py.mako) and a README for migration management.

Schema migrations:

  • Created an initial Alembic migration (aa014146bd5b) capturing the full baseline schema for all tables and relationships.
  • Added a migration (9b846e1fdacb) to include an errorMessage column in both simulations and simulationRuns tables.

Application integration and cleanup:

  • Updated the entrypoint.sh script to automatically apply all pending database migrations on startup, with guidance for first-time upgrades.
  • Removed legacy, now-unneeded migration code from app/db.py to avoid conflicts with Alembic

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Alembic migration management and the errorMessage schema update.

Changes:

  • Adds baseline and incremental migrations.
  • Configures Flask-Migrate/Alembic.
  • Runs migrations during application startup.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
.gitignore Tracks migration files.
app/db.py Removes legacy migration code.
entrypoint.sh Applies migrations at startup.
migrations/README Documents migration workflows.
migrations/alembic.ini Configures Alembic logging.
migrations/env.py Integrates Alembic with Flask.
migrations/script.py.mako Defines the revision template.
migrations/versions/baseline_and_errormessage.py Establishes the baseline schema.
migrations/versions/9b846e1fdacb_add_errormessage_to_simulations.py Adds errorMessage columns.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread entrypoint.sh Outdated
Comment on lines +211 to +214
op.drop_table('simulationRuns')
op.drop_table('projects')
op.drop_table('material_categories')
op.drop_table('files')
@mberz
mberz requested a balanced review from Copilot August 18, 2026 11:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated no new comments.

Suppressed comments (2)

README.md:131

  • flask create-db is not a safe alternative to flask db upgrade: it calls db.create_all() (manage.py:85) but never creates or stamps alembic_version. This documented fresh setup therefore leaves a database on which the entrypoint's later flask db upgrade attempts the baseline and fails because the tables already exist. Run flask db upgrade first and then flask create-db only for seeding, or make create-db record the migration revision.
# Create database and seed initial data (fresh local setup)
flask create-db

# Alternatively, apply migrations (keeps your local DB in sync with production schema)
APP_SETTINGS_MODULE=config.DevelopConfig flask db upgrade

migrations/README:49

  • Stamping every pre-Alembic database at the baseline is incorrect. A database created with the current flask create-db already has both errorMessage columns from the models, so stamping aa014146bd5b and upgrading makes revision 9b846e1fdacb add existing columns and fail. The transition procedure must distinguish legacy schemas that lack the columns from current create_all() schemas (for example, stamp the latter at head or make the migration idempotently handle this state).
flask db stamp aa014146bd5b
flask db upgrade

@mberz mberz moved this from Backlog to On hold in CHORAS planning Aug 20, 2026
@mberz
mberz marked this pull request as draft August 20, 2026 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: On hold

Development

Successfully merging this pull request may close these issues.

2 participants