"""Add todo modul

Revision ID: 15133f9f1931
Revises: 266f47a43b67
Create Date: 2014-01-03 15:21:35.594870

"""

# revision identifiers, used by Alembic.
revision = '15133f9f1931'
down_revision = '266f47a43b67'

from alembic import op
import sqlalchemy as sa


INSERTS = """
INSERT INTO "modules" VALUES(13,'todos','ringo.model.todo.Todo','Todo','Todos',NULL,NULL,'user-menu');
INSERT INTO "actions" VALUES(58,13,'List','list','icon-list-alt',NULL);
INSERT INTO "actions" VALUES(59,13,'Create','create',' icon-plus',NULL);
INSERT INTO "actions" VALUES(60,13,'Read','read/{id}','icon-eye-open',NULL);
INSERT INTO "actions" VALUES(61,13,'Update','update/{id}','icon-edit',NULL);
INSERT INTO "actions" VALUES(62,13,'Delete','delete/{id}','icon-trash',NULL);
"""
DELETES = """
DELETE FROM "actions" WHERE id = 13;
DELETE FROM "actions" WHERE id = 58;
DELETE FROM "actions" WHERE id = 59;
DELETE FROM "actions" WHERE id = 60;
DELETE FROM "actions" WHERE id = 61;
DELETE FROM "modules" WHERE id = 62;
"""


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.create_table('todos',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('gid', sa.Integer(), nullable=True),
    sa.Column('uid', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['gid'], ['usergroups.id'], ),
    sa.ForeignKeyConstraint(['uid'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    ### end Alembic commands ###
    iter_statements(INSERTS)


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('todos')
    ### end Alembic commands ###
    iter_statements(DELETES)
