"""Add form modul

Revision ID: 1b9688e1cc97
Revises: 567ddf0f6079
Create Date: 2013-12-05 14:51:39.548046

"""

# revision identifiers, used by Alembic.
revision = '1b9688e1cc97'
down_revision = '567ddf0f6079'

from alembic import op
import sqlalchemy as sa


INSERTS = """
INSERT INTO "modules" VALUES(14,'forms','ringo.model.form.Form','Form','Forms',NULL,NULL,'admin-menu',NULL);
INSERT INTO "actions" VALUES(89,14,'List','list','icon-list-alt',NULL, NULL);
INSERT INTO "actions" VALUES(90,14,'Create','create',' icon-plus',NULL, NULL);
INSERT INTO "actions" VALUES(91,14,'Read','read/{id}','icon-eye-open',NULL, NULL);
INSERT INTO "actions" VALUES(92,14,'Update','update/{id}','icon-edit',NULL, NULL);
INSERT INTO "actions" VALUES(93,14,'Delete','delete/{id}','icon-trash',NULL, NULL);
INSERT INTO "actions" VALUES(94,14,'Import','import','icon-import',NULL, NULL);
INSERT INTO "actions" VALUES(95,14,'Export','export/{id}','icon-export',NULL, NULL);
"""
DELETES = """
DELETE from modules where id = 14;
DELETE from actions where id = 89;
DELETE from actions where id = 90;
DELETE from actions where id = 91;
DELETE from actions where id = 92;
DELETE from actions where id = 93;
DELETE from actions where id = 94;
DELETE from actions where id = 95;
"""


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


def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('forms',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('gid', sa.Integer(), nullable=True),
    sa.Column('uid', sa.Integer(), nullable=True),
    sa.Column('uuid', sa.CHAR(length=32), 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('forms')
    ### end Alembic commands ###
    iter_statements(DELETES)
