diff options
author | Jessica Tallon <tsyesika@tsyesika.se> | 2015-07-31 13:45:52 +0200 |
---|---|---|
committer | Jessica Tallon <tsyesika@tsyesika.se> | 2015-07-31 15:15:24 +0200 |
commit | d7f35f6fbea8192374b1cc7e81d75ee690d0c705 (patch) | |
tree | b45bcf00330b3ba3fe43d8f260e4f7b6a4503680 | |
parent | d88fcb03e2e520da6a7d0203d660e4536108f56b (diff) | |
download | mediagoblin-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.
-rw-r--r-- | mediagoblin/db/migrations.py | 39 | ||||
-rw-r--r-- | mediagoblin/db/models.py | 14 | ||||
-rw-r--r-- | mediagoblin/edit/views.py | 3 |
3 files changed, 39 insertions, 17 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() diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 41c36764..9d57753b 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -1466,13 +1466,13 @@ with_polymorphic( [ProcessingNotification, CommentNotification]) MODELS = [ - User, MediaEntry, Tag, MediaTag, MediaComment, Collection, CollectionItem, - MediaFile, FileKeynames, MediaAttachmentFile, ProcessingMetaData, - Notification, CommentNotification, ProcessingNotification, Client, - CommentSubscription, ReportBase, CommentReport, MediaReport, UserBan, - Privilege, PrivilegeUserAssociation, - RequestToken, AccessToken, NonceTimestamp, - Activity, Generator, Location, GenericModelReference] + LocalUser, RemoteUser, User, MediaEntry, Tag, MediaTag, MediaComment, + Collection, CollectionItem, MediaFile, FileKeynames, MediaAttachmentFile, + ProcessingMetaData, Notification, CommentNotification, + ProcessingNotification, Client, CommentSubscription, ReportBase, + CommentReport, MediaReport, UserBan, Privilege, PrivilegeUserAssociation, + RequestToken, AccessToken, NonceTimestamp, Activity, Generator, Location, + GenericModelReference] """ Foundations are the default rows that are created immediately after the tables diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index 224b93de..af0d0e9b 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -314,7 +314,8 @@ def delete_account(request): request.session.delete() # Delete user account and all related media files etc.... - request.user.delete() + user = User.query.filter(User.id==user.id).first() + user.delete() # We should send a message that the user has been deleted # successfully. But we just deleted the session, so we |