-
Notifications
You must be signed in to change notification settings - Fork 119
Fix migration bootstrap failures on fresh Postgres #995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
northdpole
merged 4 commits into
OWASP:main
from
DevPatils:994-fix-migration-bootstrap-bugs
Aug 7, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0b14f0f
Add missing document_metadata column migration
DevPatils c43f5de
style: format code for consistency in migration file
DevPatils d6e7cf8
fix: correct down_revision in migration file for document_metadata co…
DevPatils f069870
Make downgrade a safe no-op to avoid dropping pre-existing data
DevPatils File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
migrations/versions/b5ac48010165_add_missing_document_metadata_column_to_.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| """add missing document_metadata column to node and cre | ||
|
|
||
| Revision ID: b5ac48010165 | ||
| Revises: d4e5f6a7b8c9 | ||
| Create Date: 2026-07-24 22:19:01.724833 | ||
|
|
||
| """ | ||
|
|
||
| from alembic import op | ||
| import sqlalchemy as sa | ||
| from sqlalchemy import inspect | ||
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "b5ac48010165" | ||
| down_revision = "d4e5f6a7b8c9" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| # Defensive: some environments (e.g. production) already have this column | ||
| # applied out-of-band without a corresponding migration ever being | ||
| # committed, so this must not assume a clean "column doesn't exist" state. | ||
| inspector = inspect(op.get_bind()) | ||
| node_columns = {c["name"] for c in inspector.get_columns("node")} | ||
| cre_columns = {c["name"] for c in inspector.get_columns("cre")} | ||
|
|
||
| if "document_metadata" not in node_columns: | ||
| with op.batch_alter_table("node", schema=None) as batch_op: | ||
| batch_op.add_column( | ||
| sa.Column("document_metadata", sa.JSON(), nullable=True) | ||
| ) | ||
|
|
||
| if "document_metadata" not in cre_columns: | ||
| with op.batch_alter_table("cre", schema=None) as batch_op: | ||
| batch_op.add_column( | ||
| sa.Column("document_metadata", sa.JSON(), nullable=True) | ||
| ) | ||
|
|
||
|
|
||
| def downgrade(): | ||
| # Intentional no-op: upgrade() only adds this column where it was | ||
| # missing, so on environments where it pre-existed (e.g. production, | ||
| # applied out-of-band) this migration never created it. Unconditionally | ||
| # dropping it here would destroy that pre-existing data on downgrade. | ||
| # There is no reliable way to tell "did *this* migration add the | ||
| # column" apart from "did it already exist," so the safe choice is to | ||
| # leave the column alone rather than risk deleting real data. | ||
| pass | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.