"""project_last_activity_at

Revision: 0174
Revision ID: ace95229377
Revises: 10e15642295c
Create Date: 2019-09-22 21:35:23.681042

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql


# revision identifiers, used by Alembic.
revision = 'ace95229377'
down_revision = '10e15642295c'
branch_labels = None
depends_on = None


def upgrade():
    op.add_column('projects', sa.Column('last_activity_at', sa.DateTime(), nullable=True))
    op.execute("UPDATE projects SET last_activity_at = cards.last_activity_at FROM cards WHERE cards.id = projects.top_level_card_id")


def downgrade():
    op.drop_column('projects', 'last_activity_at')
