1
0
Fork 0
mirror of https://gitlab.com/SIGBUS/nyaa.git synced 2024-12-22 20:50:00 +00:00
nyaa/migrations/versions/8a6a7662eb37_add_user_preferences_table.py

40 lines
1.1 KiB
Python
Raw Normal View History

2018-08-11 13:34:58 +00:00
"""Add user preferences table
2018-12-06 14:47:08 +00:00
Revision ID: 8a6a7662eb37
2018-08-11 13:34:58 +00:00
Revises: f703f911d4ae
2018-12-06 14:47:08 +00:00
Create Date: 2018-11-20 17:02:26.408532
2018-08-11 13:34:58 +00:00
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
2018-12-06 14:47:08 +00:00
revision = '8a6a7662eb37'
2018-08-11 13:34:58 +00:00
down_revision = 'f703f911d4ae'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('user_preferences',
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('hide_comments', sa.Boolean(), server_default=sa.sql.expression.false(), nullable=False),
2018-12-06 14:47:08 +00:00
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('user_id')
2018-08-11 13:34:58 +00:00
)
2018-12-06 14:47:08 +00:00
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.')
2018-08-11 13:34:58 +00:00
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('user_preferences')
# ### end Alembic commands ###