aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/db/migrations.py
diff options
context:
space:
mode:
authorJessica Tallon <tsyesika@tsyesika.se>2015-07-31 13:45:52 +0200
committerJessica Tallon <tsyesika@tsyesika.se>2015-07-31 15:15:24 +0200
commitd7f35f6fbea8192374b1cc7e81d75ee690d0c705 (patch)
treeb45bcf00330b3ba3fe43d8f260e4f7b6a4503680 /mediagoblin/db/migrations.py
parentd88fcb03e2e520da6a7d0203d660e4536108f56b (diff)
downloadmediagoblin-d7f35f6fbea8192374b1cc7e81d75ee690d0c705.tar.lz
mediagoblin-d7f35f6fbea8192374b1cc7e81d75ee690d0c705.tar.xz
mediagoblin-d7f35f6fbea8192374b1cc7e81d75ee690d0c705.zip
Add the user models to the MODELS list
This adds the two new user models (LocalUser and RemoteUser) to the MODELS list that is in models.py. This stops the strange bug that occurs if you migrate a fresh database, the two models don't exist however migrating an existing database would create them as the migrations exist.
Diffstat (limited to 'mediagoblin/db/migrations.py')
-rw-r--r--mediagoblin/db/migrations.py39
1 files changed, 30 insertions, 9 deletions
diff --git a/mediagoblin/db/migrations.py b/mediagoblin/db/migrations.py
index b6c172e0..8f9ce79b 100644
--- a/mediagoblin/db/migrations.py
+++ b/mediagoblin/db/migrations.py
@@ -36,7 +36,7 @@ from mediagoblin.db.extratypes import JSONEncoded, MutationDict
from mediagoblin.db.migration_tools import (
RegisterMigration, inspect_table, replace_table_hack)
from mediagoblin.db.models import (MediaEntry, Collection, MediaComment, User,
- Privilege, Generator)
+ Privilege, Generator, LocalUser, Location)
from mediagoblin.db.extratypes import JSONEncoded, MutationDict
@@ -1515,11 +1515,24 @@ def federation_user_migrate_data(db):
))
db.execute(user_table.update().where(user_table.c.id==user.id).values(
- updated=user.created
+ updated=user.created,
+ type=LocalUser.__mapper_args__["polymorphic_identity"]
))
db.commit()
+class User_vR2(declarative_base()):
+ __tablename__ = "rename__users"
+
+ id = Column(Integer, primary_key=True)
+ url = Column(Unicode)
+ bio = Column(UnicodeText)
+ name = Column(Unicode)
+ type = Column(Unicode)
+ created = Column(DateTime, nullable=False, default=datetime.datetime.utcnow)
+ updated = Column(DateTime, nullable=False, default=datetime.datetime.utcnow)
+ location = Column(Integer, ForeignKey(Location.id))
+
@RegisterMigration(34, MIGRATIONS)
def federation_remove_fields(db):
"""
@@ -1539,12 +1552,6 @@ def federation_remove_fields(db):
pw_hash_column = user_table.columns["pw_hash"]
pw_hash_column.drop()
- wcn_column = user_table.columns["wants_comment_notification"]
- wcn_column.drop()
-
- wants_notifications_column = user_table.columns["wants_notifications"]
- wants_notifications_column.drop()
-
license_preference_column = user_table.columns["license_preference"]
license_preference_column.drop()
@@ -1554,5 +1561,19 @@ def federation_remove_fields(db):
upload_limit_column = user_table.columns["upload_limit"]
upload_limit_column.drop()
- db.commit()
+ # SQLLite can't drop booleans -.-
+ if db.bind.url.drivername == 'sqlite':
+ # Create the new hacky table
+ User_vR2.__table__.create(db.bind)
+ db.commit()
+ new_user_table = inspect_table(metadata, "rename__users")
+ replace_table_hack(db, user_table, new_user_table)
+ else:
+ wcn_column = user_table.columns["wants_comment_notification"]
+ wcn_column.drop()
+
+ wants_notifications_column = user_table.columns["wants_notifications"]
+ wants_notifications_column.drop()
+
+ db.commit()