aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/db
diff options
context:
space:
mode:
authorJessica Tallon <tsyesika@tsyesika.se>2016-02-29 12:03:41 +0000
committerJessica Tallon <tsyesika@tsyesika.se>2016-02-29 12:33:51 +0000
commit6efcab2d69c5745c2ea9616302a08e38a5af3de6 (patch)
tree4844f7d68854db032ef9c2588adf819de3a291d8 /mediagoblin/db
parent6d38b1858c73cd7154c9fdabdc17594a820d311b (diff)
downloadmediagoblin-6efcab2d69c5745c2ea9616302a08e38a5af3de6.tar.lz
mediagoblin-6efcab2d69c5745c2ea9616302a08e38a5af3de6.tar.xz
mediagoblin-6efcab2d69c5745c2ea9616302a08e38a5af3de6.zip
Change Notification.object_id to be ID of Comemnt not TextComment
This shouldn't really effect much but it is a needed change for the future this changes the Notification.object_id to be the ID of the Comment (the link table to the comment object) rather than TextComment (the comment object itself). This is needed as now comments can be other things, other than TextComment.
Diffstat (limited to 'mediagoblin/db')
-rw-r--r--mediagoblin/db/migrations/versions/4066b9f8b84a_use_comment_link_ids_notifications.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/mediagoblin/db/migrations/versions/4066b9f8b84a_use_comment_link_ids_notifications.py b/mediagoblin/db/migrations/versions/4066b9f8b84a_use_comment_link_ids_notifications.py
new file mode 100644
index 00000000..0c023c59
--- /dev/null
+++ b/mediagoblin/db/migrations/versions/4066b9f8b84a_use_comment_link_ids_notifications.py
@@ -0,0 +1,72 @@
+"""use_comment_link_ids_notifications
+
+Revision ID: 4066b9f8b84a
+Revises: 8429e33fdf7
+Create Date: 2016-02-29 11:46:13.511318
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '4066b9f8b84a'
+down_revision = '8429e33fdf7'
+
+from alembic import op
+from sqlalchemy import MetaData
+from mediagoblin.db.migration_tools import inspect_table
+
+def upgrade():
+ """"
+ This replaces the Notification.obj with the ID of the Comment (i.e. comment
+ link) ID instead of the TextComment object.
+ """
+ db = op.get_bind()
+ metadata = MetaData(bind=db)
+ notification_table = inspect_table(metadata, "core__notifications")
+ comment_table = inspect_table(metadata, "core__comment_links")
+
+ # Get the notifications.
+ notifications = list(db.execute(notification_table.select()))
+
+ # Iterate through all the notifications
+ for notification in notifications:
+ # Lookup the Comment link object from the notification's ID
+ comment_link = db.execute(comment_table.select().where(
+ comment_table.c.comment_id == notification.object_id
+ )).first()
+
+ # Okay now we need to update the notification with the ID of the link
+ # rather than the ID of TextComment object.
+ db.execute(notification_table.update().values(
+ object_id=comment_link.id
+ ).where(
+ notification_table.c.id == notification.id
+ ))
+
+
+def downgrade():
+ """
+ This puts back the TextComment ID for the notification.object_id field
+ where we're using the Comment object (i.e. the comment link ID)
+ """
+ db = op.get_bind()
+ metadata = MetaData(bind=db)
+ notification_table = inspect_table(metadata, "core__notifications")
+ comment_table = inspect_table(metadata, "core__comment_links")
+
+ # Notificaitons
+ notifications = list(db.execute(notification_table.select()))
+
+ # Iterate through all the notifications
+ for notification in notifications:
+ # Lookup the Comment link object from the notification's ID
+ comment_link = db.execute(comment_table.select().where(
+ comment_table.c.id == notification.object_id
+ )).first()
+
+ # Update the notification with the TextComment (i.e. the comment object)
+ db.execute(notification_table.update().values(
+ object_id=comment_link.comment_id
+ ).where(
+ notification_table.c.id == notification.id
+ ))
+