diff options
author | tilly-Q <nattilypigeonfowl@gmail.com> | 2013-07-29 18:40:19 -0400 |
---|---|---|
committer | tilly-Q <nattilypigeonfowl@gmail.com> | 2013-07-29 18:40:19 -0400 |
commit | 52a355b27541597fc155dab5e4885207b12a0a7b (patch) | |
tree | 7d00edf4d9e39a6b7e4c838ca6f7cb07a4d9a51c /mediagoblin/db/migrations.py | |
parent | f26c21cd5b7998c903fa67aaf164c07743fee651 (diff) | |
parent | 08cd10d84fd89df3f0cad3835ba8ab8b8000d4b2 (diff) | |
download | mediagoblin-52a355b27541597fc155dab5e4885207b12a0a7b.tar.lz mediagoblin-52a355b27541597fc155dab5e4885207b12a0a7b.tar.xz mediagoblin-52a355b27541597fc155dab5e4885207b12a0a7b.zip |
Merge branch 'ticket-679' into OPW-Moderation-Update
Conflicts:
mediagoblin/auth/tools.py
mediagoblin/auth/views.py
mediagoblin/db/migration_tools.py
mediagoblin/db/migrations.py
mediagoblin/db/models.py
mediagoblin/decorators.py
mediagoblin/user_pages/views.py
Diffstat (limited to 'mediagoblin/db/migrations.py')
-rw-r--r-- | mediagoblin/db/migrations.py | 100 |
1 files changed, 93 insertions, 7 deletions
diff --git a/mediagoblin/db/migrations.py b/mediagoblin/db/migrations.py index 247298ac..53df7954 100644 --- a/mediagoblin/db/migrations.py +++ b/mediagoblin/db/migrations.py @@ -289,10 +289,99 @@ def unique_collections_slug(db): db.commit() -class ReportBase_v0(declarative_base()): +@RegisterMigration(11, MIGRATIONS) +def drop_token_related_User_columns(db): """ - + Drop unneeded columns from the User table after switching to using + itsdangerous tokens for email and forgot password verification. """ + metadata = MetaData(bind=db.bind) + user_table = inspect_table(metadata, 'core__users') + + + verification_key = user_table.columns['verification_key'] + fp_verification_key = user_table.columns['fp_verification_key'] + fp_token_expire = user_table.columns['fp_token_expire'] + + verification_key.drop() + fp_verification_key.drop() + fp_token_expire.drop() + + db.commit() + + +class CommentSubscription_v0(declarative_base()): + __tablename__ = 'core__comment_subscriptions' + id = Column(Integer, primary_key=True) + + created = Column(DateTime, nullable=False, default=datetime.datetime.now) + + media_entry_id = Column(Integer, ForeignKey(MediaEntry.id), nullable=False) + + user_id = Column(Integer, ForeignKey(User.id), nullable=False) + + + notify = Column(Boolean, nullable=False, default=True) + send_email = Column(Boolean, nullable=False, default=True) + + +class Notification_v0(declarative_base()): + __tablename__ = 'core__notifications' + id = Column(Integer, primary_key=True) + type = Column(Unicode) + + created = Column(DateTime, nullable=False, default=datetime.datetime.now) + + user_id = Column(Integer, ForeignKey(User.id), nullable=False, + index=True) + seen = Column(Boolean, default=lambda: False, index=True) + + +class CommentNotification_v0(Notification_v0): + __tablename__ = 'core__comment_notifications' + id = Column(Integer, ForeignKey(Notification_v0.id), primary_key=True) + + subject_id = Column(Integer, ForeignKey(MediaComment.id)) + + +class ProcessingNotification_v0(Notification_v0): + __tablename__ = 'core__processing_notifications' + + id = Column(Integer, ForeignKey(Notification_v0.id), primary_key=True) + + subject_id = Column(Integer, ForeignKey(MediaEntry.id)) + + +@RegisterMigration(12, MIGRATIONS) +def add_new_notification_tables(db): + metadata = MetaData(bind=db.bind) + + user_table = inspect_table(metadata, 'core__users') + mediaentry_table = inspect_table(metadata, 'core__media_entries') + mediacomment_table = inspect_table(metadata, 'core__media_comments') + + CommentSubscription_v0.__table__.create(db.bind) + + Notification_v0.__table__.create(db.bind) + CommentNotification_v0.__table__.create(db.bind) + ProcessingNotification_v0.__table__.create(db.bind) + + +@RegisterMigration(13, MIGRATIONS) +def pw_hash_nullable(db): + """Make pw_hash column nullable""" + metadata = MetaData(bind=db.bind) + user_table = inspect_table(metadata, "core__users") + + user_table.c.pw_hash.alter(nullable=True) + + # sqlite+sqlalchemy seems to drop this constraint during the + # migration, so we add it back here for now a bit manually. + if db.bind.url.drivername == 'sqlite': + constraint = UniqueConstraint('username', table=user_table) + constraint.create() + +class ReportBase_v0(declarative_base()): __tablename__ = 'core__reports' id = Column(Integer, primary_key=True) reporter_id = Column(Integer, ForeignKey(User.id), nullable=False) @@ -302,7 +391,6 @@ class ReportBase_v0(declarative_base()): discriminator = Column('type', Unicode(50)) __mapper_args__ = {'polymorphic_on': discriminator} - class CommentReport_v0(ReportBase_v0): __tablename__ = 'core__reports_on_comments' __mapper_args__ = {'polymorphic_identity': 'comment_report'} @@ -316,14 +404,13 @@ class MediaReport_v0(ReportBase_v0): __mapper_args__ = {'polymorphic_identity': 'media_report'} id = Column('id',Integer, ForeignKey('core__reports.id'), primary_key=True) - media_entry_id = Column(Integer, ForeignKey(MediaEntry.id), nullable=False) + media_entry_id = Column(Integer, ForeignKey(MediaEntry.i class ArchivedReport_v0(ReportBase_v0): __tablename__ = 'core__reports_archived' __mapper_args__ = {'polymorphic_identity': 'archived_report'} id = Column('id',Integer, ForeignKey('core__reports.id')) - media_entry_id = Column(Integer, ForeignKey(MediaEntry.id)) comment_id = Column(Integer, ForeignKey(MediaComment.id)) resolver_id = Column(Integer, ForeignKey(User.id), nullable=False) @@ -344,7 +431,6 @@ class Privilege_v0(declarative_base()): class PrivilegeUserAssociation_v0(declarative_base()): __tablename__ = 'core__privileges_users' - group_id = Column( 'core__privilege_id', Integer, @@ -356,7 +442,7 @@ class PrivilegeUserAssociation_v0(declarative_base()): ForeignKey(Privilege.id), primary_key=True) -@RegisterMigration(11, MIGRATIONS) +@RegisterMigration(14, MIGRATIONS) def create_moderation_tables(db): ReportBase_v0.__table__.create(db.bind) CommentReport_v0.__table__.create(db.bind) |