"""Add fitter tables

Revision ID: 514c4c54871
Revises: 44d3aa89e8c
Create Date: 2015-06-01 10:29:41.478815

"""

# revision identifiers, used by Alembic.
revision = '514c4c54871'
down_revision = '44d3aa89e8c'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa


def upgrade(engine_name):
    globals()["upgrade_%s" % engine_name]()


def downgrade(engine_name):
    globals()["downgrade_%s" % engine_name]()





def upgrade_account():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('fitter_last_run',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('last_run', sa.DateTime(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('fitter_tenants',
    sa.Column('id', sa.String(length=100), nullable=False),
    sa.Column('name', sa.Text(), nullable=False),
    sa.Column('info', sa.Text(), nullable=True),
    sa.Column('created', sa.DateTime(), nullable=False),
    sa.Column('last_collected', sa.DateTime(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('fitter_resources',
    sa.Column('id', sa.String(length=100), nullable=False),
    sa.Column('tenant_id', sa.String(length=100), nullable=False),
    sa.Column('info', sa.Text(), nullable=True),
    sa.Column('created', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['tenant_id'], ['fitter_tenants.id'], ),
    sa.PrimaryKeyConstraint('id', 'tenant_id')
    )
    op.create_table('fitter_sales_orders',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('tenant_id', sa.String(length=100), nullable=False),
    sa.Column('start', sa.DateTime(), nullable=False),
    sa.Column('end', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['tenant_id'], ['fitter_tenants.id'], ),
    sa.PrimaryKeyConstraint('id', 'tenant_id', 'start', 'end')
    )
    op.create_table('fitter_usage_entry',
    sa.Column('service', sa.String(length=100), nullable=False),
    sa.Column('unit', sa.String(length=100), nullable=True),
    sa.Column('volume', sa.Numeric(precision=20, scale=2), nullable=False),
    sa.Column('resource_id', sa.String(length=100), nullable=False),
    sa.Column('tenant_id', sa.String(length=100), nullable=False),
    sa.Column('start', sa.DateTime(), nullable=False),
    sa.Column('end', sa.DateTime(), nullable=False),
    sa.Column('created', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['resource_id', 'tenant_id'], ['fitter_resources.id', 'fitter_resources.tenant_id'], name='fk_resource_constraint'),
    sa.PrimaryKeyConstraint('service', 'resource_id', 'tenant_id', 'start', 'end')
    )
    ### end Alembic commands ###


def downgrade_account():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('fitter_usage_entry')
    op.drop_table('fitter_sales_orders')
    op.drop_table('fitter_resources')
    op.drop_table('fitter_tenants')
    op.drop_table('fitter_last_run')
    ### end Alembic commands ###


def upgrade_fitter():
    pass


def downgrade_fitter():
    pass

