"""Add printtemplate modul

Revision ID: 4b7b8545a7a
Revises: 1a78ab0751fb
Create Date: 2014-02-06 10:30:40.142786

"""

# revision identifiers, used by Alembic.
revision = '4b7b8545a7a'
down_revision = '1a78ab0751fb'

from alembic import op
import sqlalchemy as sa


INSERTS = """
INSERT INTO "modules" VALUES(15,'printtemplates','ringo.model.printtemplate.Printtemplate','Printtemplate','Printtemplates',NULL,'%s|id','admin-menu','8a9fe79593e04159a050f44d038889fd');
INSERT INTO "actions" VALUES(96,15,'List','list','icon-list-alt',NULL,'87d18e63882a469584133488da7e7120');
INSERT INTO "actions" VALUES(97,15,'Create','create',' icon-plus',NULL,'dc6e5547927b43b3a7fbcae117a11af2');
INSERT INTO "actions" VALUES(98,15,'Read','read/{id}','icon-eye-open',NULL,'116a4a668f4b4e6480a6d1f6f9a38228');
INSERT INTO "actions" VALUES(99,15,'Update','update/{id}','icon-edit',NULL,'19d0702b95f341b398575782bc0eb1fc');
INSERT INTO "actions" VALUES(100,15,'Delete','delete/{id}','icon-trash',NULL,'59aed4c4f9e8455cbc70d5ee9ebc80c1');
INSERT INTO "actions" VALUES(101,15,'Import','import','icon-import',NULL,'47f1c8f9ba2d4ec8b363e6b07f44d5cb');
INSERT INTO "actions" VALUES(102,15,'Export','export/{id}','icon-export',NULL,'bda7f92285ee4dffbf207e9c837b5741');
INSERT INTO "actions" VALUES(103,15,'Download','download/{id}','icon-download',NULL,'bfa7f92285ee4dffbf207e9c837b5741');
"""
DELETES = """
DELETE FROM "actions" WHERE id = 96;
DELETE FROM "actions" WHERE id = 97;
DELETE FROM "actions" WHERE id = 98;
DELETE FROM "actions" WHERE id = 99;
DELETE FROM "actions" WHERE id = 100;
DELETE FROM "actions" WHERE id = 101;
DELETE FROM "actions" WHERE id = 102;
DELETE FROM "actions" WHERE id = 103;
DELETE FROM "modules" WHERE id = 15;
"""


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('printtemplates',
    sa.Column('uuid', sa.CHAR(length=32), nullable=True),
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('mid', sa.Integer(), nullable=True),
    sa.Column('name', sa.Text(), nullable=True),
    sa.Column('data', sa.LargeBinary(), nullable=True),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('size', sa.Integer(), nullable=True),
    sa.Column('mime', sa.Text(), nullable=True),
    sa.Column('gid', sa.Integer(), nullable=True),
    sa.Column('uid', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['gid'], ['usergroups.id'], ),
    sa.ForeignKeyConstraint(['mid'], ['modules.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('printtemplates')
    ### end Alembic commands ###
    iter_statements(DELETES)
