aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/db/migrations.py
diff options
context:
space:
mode:
authorJessica Tallon <tsyesika@tsyesika.se>2015-08-19 16:56:49 +0200
committerJessica Tallon <tsyesika@tsyesika.se>2015-08-19 17:18:37 +0200
commit35fbad47d7e74faa7eaa87ade534a9fb10df6d36 (patch)
treee7171e192cad53465400d902dd6345c1e8e5a30c /mediagoblin/db/migrations.py
parentc9f6afe291e76f4f0deb6467b32ba34861b850f3 (diff)
downloadmediagoblin-35fbad47d7e74faa7eaa87ade534a9fb10df6d36.tar.lz
mediagoblin-35fbad47d7e74faa7eaa87ade534a9fb10df6d36.tar.xz
mediagoblin-35fbad47d7e74faa7eaa87ade534a9fb10df6d36.zip
Change structure of MediaEntry and add migration
This makes the changes needed for federating MediaEntry objects as well as adding the migration and necessary methods to get the public_id just in time (JIT).
Diffstat (limited to 'mediagoblin/db/migrations.py')
-rw-r--r--mediagoblin/db/migrations.py45
1 files changed, 42 insertions, 3 deletions
diff --git a/mediagoblin/db/migrations.py b/mediagoblin/db/migrations.py
index 8f9ce79b..00b0add1 100644
--- a/mediagoblin/db/migrations.py
+++ b/mediagoblin/db/migrations.py
@@ -1461,14 +1461,14 @@ def federation_user_create_tables(db):
"""
Create all the tables
"""
- metadata = MetaData(bind=db.bind)
- user_table = inspect_table(metadata, "core__users")
-
# Create tables needed
LocalUser_V0.__table__.create(db.bind)
RemoteUser_V0.__table__.create(db.bind)
db.commit()
+ metadata = MetaData(bind=db.bind)
+ user_table = inspect_table(metadata, "core__users")
+
# Create the fields
updated_column = Column(
"updated",
@@ -1575,5 +1575,44 @@ def federation_remove_fields(db):
wants_notifications_column = user_table.columns["wants_notifications"]
wants_notifications_column.drop()
+ db.commit()
+
+@RegisterMigration(35, MIGRATIONS)
+def federation_media_entry(db):
+ metadata = MetaData(bind=db.bind)
+ media_entry_table = inspect_table(metadata, "core__media_entries")
+
+ # Add new fields
+ public_id_column = Column(
+ "public_id",
+ Unicode,
+ unique=True,
+ nullable=True
+ )
+ public_id_column.create(
+ media_entry_table,
+ unique_name="media_public_id"
+ )
+
+ remote_column = Column(
+ "remote",
+ Boolean,
+ default=False
+ )
+ remote_column.create(media_entry_table)
+
+ updated_column = Column(
+ "updated",
+ DateTime,
+ default=datetime.datetime.utcnow,
+ )
+ updated_column.create(media_entry_table)
+
+ # Data migration
+ for entry in db.execute(media_entry_table.select()):
+ db.execute(media_entry_table.update().values(
+ updated=entry.created,
+ remote=False
+ ))
db.commit()