-
Notifications
You must be signed in to change notification settings - Fork 115
Fix migration bootstrap failures on fresh Postgress #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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| """add missing document_metadata column to node and cre | ||
|
|
||
| Revision ID: b5ac48010165 | ||
| Revises: c7d8e9f0a1b2 | ||
| 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 = 'c7d8e9f0a1b2' | ||
| 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(): | ||
| with op.batch_alter_table("cre", schema=None) as batch_op: | ||
| batch_op.drop_column("document_metadata") | ||
|
|
||
| with op.batch_alter_table("node", schema=None) as batch_op: | ||
| batch_op.drop_column("document_metadata") | ||
|
Comment on lines
+37
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🔴 Critical | 🏗️ Heavy lift Do not unconditionally drop columns this migration may not own. Because 🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
Repository: OWASP/OpenCRE
Length of output: 17258
🏁 Script executed:
Repository: OWASP/OpenCRE
Length of output: 3951
Preserve legacy
metadata_jsonvalues before settingdocument_metadata.The ORM for
NodeandCREreadsmetadata_jsonmapped to the SQL columndocument_metadata, and benchmark parity also supports schemas that havemetadata_jsoninstead. This migration only adds an emptydocument_metadatacolumn whenmetadata_jsonexists, so existing metadata becomes inaccessible. Rename/copymetadata_jsontodocument_metadatafor both tables, and handle the case where both columns already exist.🤖 Prompt for AI Agents