"""Track the lifetime start and end for tags to allow the state of a repository to be rewound.

Revision ID: 509d2857566f
Revises: 3e2d38b52a75
Create Date: 2015-02-13 14:35:38.939049

"""

# revision identifiers, used by Alembic.
revision = '509d2857566f'
down_revision = '3e2d38b52a75'

from alembic import op
import sqlalchemy as sa


def upgrade(tables):
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('repositorytag', sa.Column('lifetime_end_ts', sa.Integer(), nullable=True))
    op.add_column('repositorytag', sa.Column('lifetime_start_ts', sa.Integer(), nullable=False, server_default="0"))
    op.create_index('repositorytag_lifetime_end_ts', 'repositorytag', ['lifetime_end_ts'], unique=False)
    op.drop_index('repositorytag_repository_id_name', table_name='repositorytag')
    op.create_index('repositorytag_repository_id_name', 'repositorytag', ['repository_id', 'name'], unique=False)
    op.add_column('user', sa.Column('removed_tag_expiration_s', sa.Integer(), nullable=False, server_default="1209600"))
    ### end Alembic commands ###


def downgrade(tables):
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('user', 'removed_tag_expiration_s')
    op.drop_index('repositorytag_repository_id_name', table_name='repositorytag')
    op.create_index('repositorytag_repository_id_name', 'repositorytag', ['repository_id', 'name'], unique=True)
    op.drop_index('repositorytag_lifetime_end_ts', table_name='repositorytag')
    op.drop_column('repositorytag', 'lifetime_start_ts')
    op.drop_column('repositorytag', 'lifetime_end_ts')
    ### end Alembic commands ###
