From 48e8ac875ae17e8560506acda5ba7378ebffdf44 Mon Sep 17 00:00:00 2001 From: Gulliver Date: Sun, 20 Jun 2021 15:08:03 +0200 Subject: [PATCH] added migration for changed datamodel (split user<->user_profile) --- ...64c615e8_split_user_to_user_and_profile.py | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 migrations/versions/de2164c615e8_split_user_to_user_and_profile.py diff --git a/migrations/versions/de2164c615e8_split_user_to_user_and_profile.py b/migrations/versions/de2164c615e8_split_user_to_user_and_profile.py new file mode 100644 index 0000000..fa831fd --- /dev/null +++ b/migrations/versions/de2164c615e8_split_user_to_user_and_profile.py @@ -0,0 +1,44 @@ +"""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')