From 7555d1084fbdba409085ecd9eda817bec653a63d Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Mon, 29 Feb 2016 19:18:42 +0000 Subject: [PATCH] Fixes #5421 - Ensures Report.object_id is nullable It seems there was a commit for a while where the migration was making Report.object_id NOT NULL and this caused an errror when a report deleted the associated object (media). This migrtion checks it's nullable and if not, alters it so it is. --- ...bd2_ensure_report_object_id_is_nullable.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 mediagoblin/db/migrations/versions/228916769bd2_ensure_report_object_id_is_nullable.py diff --git a/mediagoblin/db/migrations/versions/228916769bd2_ensure_report_object_id_is_nullable.py b/mediagoblin/db/migrations/versions/228916769bd2_ensure_report_object_id_is_nullable.py new file mode 100644 index 00000000..596b87de --- /dev/null +++ b/mediagoblin/db/migrations/versions/228916769bd2_ensure_report_object_id_is_nullable.py @@ -0,0 +1,33 @@ +"""ensure Report.object_id is nullable + +Revision ID: 228916769bd2 +Revises: 3145accb8fe3 +Create Date: 2016-02-29 18:54:37.295185 + +""" + +# revision identifiers, used by Alembic. +revision = '228916769bd2' +down_revision = '3145accb8fe3' + +from alembic import op +from sqlalchemy import MetaData +from mediagoblin.db.migration_tools import inspect_table + +def upgrade(): + """ + This ensures that the Report.object_id field is nullable, it seems for a + short period of time it could have been NOT NULL but was fixed later. + """ + db = op.get_bind() + metadata = MetaData(bind=db) + report_table = inspect_table(metadata, "core__reports") + + # Check if the field has nullable on + object_id_field = report_table.columns["object_id"] + if object_id_field.nullable != True: + # We have to alter this. + object_id_field.alter(nullable=True) + +def downgrade(): + pass -- 2.25.1