Fixes #5421 - Ensures Report.object_id is nullable
authorJessica Tallon <tsyesika@tsyesika.se>
Mon, 29 Feb 2016 19:18:42 +0000 (19:18 +0000)
committerJessica Tallon <tsyesika@tsyesika.se>
Mon, 29 Feb 2016 19:18:42 +0000 (19:18 +0000)
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.

mediagoblin/db/migrations/versions/228916769bd2_ensure_report_object_id_is_nullable.py [new file with mode: 0644]

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 (file)
index 0000000..596b87d
--- /dev/null
@@ -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