"""Added new fields to the activity

Revision ID: 18cc13347b55
Revises: 545a4f2b2e3e
Create Date: 2016-10-21 15:41:15.694876

"""

# revision identifiers, used by Alembic.
revision = '18cc13347b55'
down_revision = '545a4f2b2e3e'

from alembic import op
import sqlalchemy as sa


INSERTS = """"""
DELETES = """"""


def iter_statements(stmts):
    for st in [x for x in stmts.split('\n') if x]:
        op.execute(st)


def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('activitys', sa.Column('date', sa.Date(), nullable=True))
    op.add_column('activitys', sa.Column('description', sa.String(), nullable=False))
    op.add_column('activitys', sa.Column('distance', sa.Integer(), nullable=True))
    op.add_column('activitys', sa.Column('duration', sa.Interval(), nullable=True))
    op.add_column('activitys', sa.Column('elevation', sa.Integer(), nullable=True))
    op.add_column('activitys', sa.Column('heartrate', sa.Integer(), nullable=True))
    op.add_column('activitys', sa.Column('rating', sa.Integer(), nullable=True))
    op.add_column('activitys', sa.Column('sport', sa.Integer(), nullable=True))
    op.add_column('activitys', sa.Column('title', sa.String(), nullable=False))
    op.create_foreign_key('fk_activitys_uid_users', 'activitys', 'users', ['uid'], ['id'], use_alter=True)
    op.create_foreign_key('fk_activitys_gid_usergroups', 'activitys', 'usergroups', ['gid'], ['id'], use_alter=True)
    ### end Alembic commands ###
    iter_statements(INSERTS)


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint('fk_activitys_gid_usergroups', 'activitys', type_='foreignkey')
    op.drop_constraint('fk_activitys_uid_users', 'activitys', type_='foreignkey')
    op.drop_column('activitys', 'title')
    op.drop_column('activitys', 'sport')
    op.drop_column('activitys', 'rating')
    op.drop_column('activitys', 'heartrate')
    op.drop_column('activitys', 'elevation')
    op.drop_column('activitys', 'duration')
    op.drop_column('activitys', 'distance')
    op.drop_column('activitys', 'description')
    op.drop_column('activitys', 'date')
    ### end Alembic commands ###
    iter_statements(DELETES)
