Fix removal of ActivityIntermediatory migration
authorJessica Tallon <tsyesika@tsyesika.se>
Wed, 24 Jun 2015 19:22:03 +0000 (21:22 +0200)
committerJessica Tallon <tsyesika@tsyesika.se>
Wed, 24 Jun 2015 19:43:16 +0000 (21:43 +0200)
The migration had a problem where other tables still referenced the migration
as well as a typo in an earlier migration. They have both been fixed and tested
on PostgreSQL and SQLite3.

This also fixes a bug where sometimes when creating an activity it'd raise an
Exception as the object hadn't got an ID. This has been fixed globally with a
fix to the create_activity federation tool.

mediagoblin/db/migrations.py
mediagoblin/tools/federation.py

index 9ecd6e6225a0d55e0c1c302b4c5772bbcb1ec933..4f2f8915352478dba6d26fe244c4ec393839af0b 100644 (file)
@@ -1289,10 +1289,10 @@ def add_foreign_key_fields(db):
     activity_table = inspect_table(metadata, "core__activities")
 
     # Create column and add to model.
-    object_column = Column("temp_object", Integer, ForeignKey(GenericModelReference_V0))
+    object_column = Column("temp_object", Integer, ForeignKey(GenericModelReference_V0.id))
     object_column.create(activity_table)
 
-    target_column = Column("temp_target", Integer, ForeignKey(GenericModelReference_V0))
+    target_column = Column("temp_target", Integer, ForeignKey(GenericModelReference_V0.id))
     target_column.create(activity_table)
 
     # Commit this to the database
@@ -1406,6 +1406,23 @@ def remove_activityintermediator(db):
     """
     metadata = MetaData(bind=db.bind)
 
+    # Remove the columns which reference the AI
+    collection_table = inspect_table(metadata, "core__collections")
+    collection_ai_column = collection_table.columns["activity"]
+    collection_ai_column.drop()
+
+    media_entry_table = inspect_table(metadata, "core__media_entries")
+    media_entry_ai_column = media_entry_table.columns["activity"]
+    media_entry_ai_column.drop()
+
+    comments_table = inspect_table(metadata, "core__media_comments")
+    comments_ai_column = comments_table.columns["activity"]
+    comments_ai_column.drop()
+
+    user_table = inspect_table(metadata, "core__users")
+    user_ai_column = user_table.columns["activity"]
+    user_ai_column.drop()
+
     # Drop the table
     ai_table = inspect_table(metadata, "core__activity_intermediators")
     ai_table.drop()
index e7593a92ab20e79557306f4ae3c4d0bf990a5dae..39b465bf738b5e86f5fc3bc8100db7b9799adf81 100644 (file)
@@ -71,6 +71,10 @@ def create_activity(verb, obj, actor, target=None, generator=None):
             )
             generator.save()
 
+    # Ensure the object has an ID which is needed by the activity.
+    obj.save(commit=False)
+
+    # Create the activity
     activity = Activity(verb=verb)
     activity.object = obj