"""tiktik_sounds.first_seen Revision ID: 4c649d16f395 Revises: 89b37a7beffb Create Date: 2019-06-21 10:59:54.406197 """ # revision identifiers, used by Alembic. revision = '4c649d16f395' down_revision = '89b37a7beffb' branch_labels = None depends_on = None from alembic import op import sqlalchemy as sa def upgrade(): ### commands auto generated by Alembic - please adjust! ### op.add_column('tiktok_sounds', sa.Column('first_seen', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False)) op.execute(''' with first_dates as ( select ttid, min(as_of) min_as_of from tiktok_sound_stats group by ttid ) update tiktok_sounds set first_seen = f.min_as_of from first_dates f where f.ttid = tiktok_sounds.ttid ''') ### end Alembic commands ### def downgrade(): ### commands auto generated by Alembic - please adjust! ### op.drop_column('tiktok_sounds', 'first_seen') ### end Alembic commands ###