"""empty message

Revision ID: 7d4c312300d1
Revises: None
Create Date: 2016-01-02 14:55:11.799969

"""

# revision identifiers, used by Alembic.
revision = '7d4c312300d1'
down_revision = None

from alembic import op
import sqlalchemy as sa


def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('accounts',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('parent_id', sa.Integer(), nullable=True),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.Column('type', sa.Enum('liability', 'asset', 'income', 'expense', 'equity', name='account_type'), nullable=False),
    sa.ForeignKeyConstraint(['parent_id'], ['accounts.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_table('payees',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_table('transactions',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('date', sa.Date(), nullable=False),
    sa.Column('payee_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['payee_id'], ['payees.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('splits',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('transaction_id', sa.Integer(), nullable=False),
    sa.Column('account_id', sa.Integer(), nullable=False),
    sa.Column('amount', sa.Float(), nullable=True),
    sa.Column('reconciled_status', sa.Enum('not_reconciled', 'cleared', 'reconciled', name='reconciled_status'), nullable=True),
    sa.Column('is_primary_split', sa.Boolean(), nullable=True),
    sa.ForeignKeyConstraint(['account_id'], ['accounts.id'], ),
    sa.ForeignKeyConstraint(['transaction_id'], ['transactions.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('transaction_id', 'account_id', name='transaction__account__uix')
    )
    with op.batch_alter_table('splits', schema=None) as batch_op:
        batch_op.create_index('transaction__primary_split__uix', ['transaction_id', 'is_primary_split'], unique=True, sqlite_where=sa.text(u'is_primary_split != 0'), postgresql_where=sa.text(u'is_primary_split != 0'))

    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('splits', schema=None) as batch_op:
        batch_op.drop_index('transaction__primary_split__uix')

    op.drop_table('splits')
    op.drop_table('transactions')
    op.drop_table('payees')
    op.drop_table('accounts')
    ### end Alembic commands ###
