"""tiktok_users_influencer_fix Revision ID: f1caf912fa57 Revises: 2430e8dab13b Create Date: 2019-12-03 10:01:11.743655 """ # revision identifiers, used by Alembic. revision = 'f1caf912fa57' down_revision = '2430e8dab13b' branch_labels = None depends_on = None from alembic import op import sqlalchemy as sa from sqlalchemy.dialects import postgresql def upgrade(): # Change users_tt_influencers to use the unique_id instead of ttid, since we don't have ttid until first scrape. op.add_column('users_tt_influencers', sa.Column('unique_id', sa.String(), autoincrement=False, nullable=True)) op.execute(''' alter table users_tt_influencers drop constraint users_tt_influencers_pkey; ALTER TABLE users_tt_influencers ALTER COLUMN ttid DROP NOT NULL; ''') # populate unique_id for existing records: op.execute(''' update users_tt_influencers set unique_id = tu.unique_id from tiktok_users tu where tu.ttid = users_tt_influencers.ttid; ''') ### end Alembic commands ### def downgrade(): ### commands auto generated by Alembic - please adjust! ### op.add_column('users_tt_influencers', sa.Column('ttid', sa.VARCHAR(), autoincrement=False, nullable=False)) op.drop_column('users_tt_influencers', 'unique_id') ### end Alembic commands ###