ki-backend/migrations/versions/de2164c615e8_split_user_to_user_and_profile.py

45 lines
1.5 KiB
Python

"""split user to user and profile
Revision ID: de2164c615e8
Revises: 575a8924eb16
Create Date: 2021-06-20 14:17:02.102076
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'de2164c615e8'
down_revision = '575a8924eb16'
branch_labels = None
depends_on = None
def upgrade():
op.create_table('user_profile',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=True),
sa.Column('pronouns', sa.String(length=25), nullable=True),
sa.Column('volunteerwork', sa.String(length=4000), nullable=True),
sa.Column('freetext', sa.String(length=4000), nullable=True),
sa.Column('created', sa.DateTime(), nullable=False),
sa.Column('updated', sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint('id'),
)
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
op.execute("INSERT INTO user_profile (user_id,pronouns,volunteerwork,freetext,created,updated) SELECT id,pronouns,volunteerwork,freetext,created,updated FROM user")
op.drop_column("user","pronouns")
op.drop_column("user","volunteerwork")
op.drop_column("user","freetext")
def downgrade():
op.add_column("user", Column('pronouns', sa.String(length=25), nullable=True))
op.add_column("user", Column("volunteerwork",sa.String(length=4000), nullable=True))
op.add_column("user", Column("freetext",sa.String(length=4000), nullable=True))
# tbd update user table fields from user profile fields
op.drop_table('user_profile')