diff options
author | Jessica Tallon <tsyesika@tsyesika.se> | 2016-02-29 19:18:42 +0000 |
---|---|---|
committer | Jessica Tallon <tsyesika@tsyesika.se> | 2016-02-29 19:18:42 +0000 |
commit | 7555d1084fbdba409085ecd9eda817bec653a63d (patch) | |
tree | 35e48d9339752240b2462df645c3f927b3d2bc30 | |
parent | ab14059538e7d6961ed279219fdc6b68d45a7741 (diff) | |
download | mediagoblin-7555d1084fbdba409085ecd9eda817bec653a63d.tar.lz mediagoblin-7555d1084fbdba409085ecd9eda817bec653a63d.tar.xz mediagoblin-7555d1084fbdba409085ecd9eda817bec653a63d.zip |
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.
-rw-r--r-- | mediagoblin/db/migrations/versions/228916769bd2_ensure_report_object_id_is_nullable.py | 33 |
1 files changed, 33 insertions, 0 deletions
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 |