mirror of
https://gitlab.com/SIGBUS/nyaa.git
synced 2024-12-30 17:31:54 +00:00
parent
e04bbdfbf9
commit
4fea839f51
|
@ -1,8 +1,8 @@
|
|||
"""Add user preferences table
|
||||
|
||||
Revision ID: 0b03879cdb05
|
||||
Revision ID: 8a6a7662eb37
|
||||
Revises: f703f911d4ae
|
||||
Create Date: 2018-08-11 13:23:01.863441
|
||||
Create Date: 2018-11-20 17:02:26.408532
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
|
@ -10,7 +10,7 @@ import sqlalchemy as sa
|
|||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '0b03879cdb05'
|
||||
revision = '8a6a7662eb37'
|
||||
down_revision = 'f703f911d4ae'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
@ -19,13 +19,17 @@ depends_on = None
|
|||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('user_preferences',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('user_id', sa.Integer(), nullable=False),
|
||||
sa.Column('hide_comments', sa.Boolean(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('user_id')
|
||||
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('user_id')
|
||||
)
|
||||
|
||||
connection = op.get_bind()
|
||||
|
||||
print('Populating user_preferences...')
|
||||
connection.execute(sa.sql.text('INSERT INTO user_preferences (user_id) SELECT id FROM users'))
|
||||
print('Done.')
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
|
@ -647,14 +647,13 @@ class User(db.Model):
|
|||
class UserPreferences(db.Model):
|
||||
__tablename__ = 'user_preferences'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), unique=True, nullable=False)
|
||||
user_id = db.Column(db.Integer, db.ForeignKey('users.id', ondelete='CASCADE'), primary_key=True)
|
||||
|
||||
def __init__(self, user_id):
|
||||
self.user_id = user_id
|
||||
|
||||
def __repr__(self):
|
||||
return '<UserPreferences %r>' % self.id
|
||||
return '<UserPreferences %r>' % self.user_id
|
||||
|
||||
user = db.relationship('User', back_populates='preferences')
|
||||
hide_comments = db.Column(db.Boolean, nullable=False, default=False)
|
||||
|
|
Loading…
Reference in a new issue