"""0.6.1

Revision ID: 329d9f86b93b
Revises: None
Create Date: 2013-09-23 21:21:38.789947

"""

# revision identifiers, used by Alembic.
revision = '329d9f86b93b'
down_revision = None

from alembic import op
import sqlalchemy as sa


INSERTS = """INSERT INTO "user_settings" VALUES(1,'{}');
INSERT INTO "modules" VALUES(1,'modules','ringo.model.modul.ModulItem','Modul','Modules',NULL,NULL,'admin-menu');
INSERT INTO "modules" VALUES(2,'actions','ringo.model.modul.ActionItem','Action','Actions',NULL,NULL,'admin-menu');
INSERT INTO "modules" VALUES(3,'users','ringo.model.user.User','User','Users',NULL,NULL,'admin-menu');
INSERT INTO "modules" VALUES(4,'usergroups','ringo.model.user.Usergroup','Usergroup','Usergroups',NULL,NULL,'admin-menu');
INSERT INTO "modules" VALUES(5,'roles','ringo.model.user.Role','Role','Roles',NULL,NULL,'admin-menu');
INSERT INTO "modules" VALUES(6,'profiles','ringo.model.user.Profile','Profile','Profiles',NULL,NULL,'admin-menu');
INSERT INTO "modules" VALUES(7,'appointments','ringo.model.appointment.Appointment','Appointment','Appointments',NULL,NULL,'header-menu');
INSERT INTO "modules" VALUES(8,'files','ringo.model.file.File','File','Files',NULL,NULL,'header-menu');
INSERT INTO "roles" VALUES(1,'admin',1);
INSERT INTO "roles" VALUES(2,'user',0);
INSERT INTO "usergroups" VALUES(1,'admins');
INSERT INTO "usergroups" VALUES(2,'users');
INSERT INTO "nm_usergroup_roles" VALUES(1,1);
INSERT INTO "nm_usergroup_roles" VALUES(2,2);
INSERT INTO "users" VALUES(1,'admin','5ebe2294ecd0e0f08eab7690d2a6ee69',1,'0e3cc848-22f6-4ff7-a562-12baf3037439',1,1);
INSERT INTO "actions" VALUES(1,1,'List','list','icon-list-alt',NULL);
INSERT INTO "actions" VALUES(2,1,'Read','read/{id}','icon-eye-open',NULL);
INSERT INTO "actions" VALUES(3,1,'Update','update/{id}','icon-edit',NULL);
INSERT INTO "actions" VALUES(4,3,'List','list','icon-list-alt',NULL);
INSERT INTO "actions" VALUES(5,3,'Create','create',' icon-plus',NULL);
INSERT INTO "actions" VALUES(6,3,'Read','read/{id}','icon-eye-open',NULL);
INSERT INTO "actions" VALUES(7,3,'Update','update/{id}','icon-edit',NULL);
INSERT INTO "actions" VALUES(8,3,'Delete','delete/{id}','icon-trash',NULL);
INSERT INTO "actions" VALUES(9,4,'List','list','icon-list-alt',NULL);
INSERT INTO "actions" VALUES(10,4,'Create','create',' icon-plus',NULL);
INSERT INTO "actions" VALUES(11,4,'Read','read/{id}','icon-eye-open',NULL);
INSERT INTO "actions" VALUES(12,4,'Update','update/{id}','icon-edit',NULL);
INSERT INTO "actions" VALUES(13,4,'Delete','delete/{id}','icon-trash',NULL);
INSERT INTO "actions" VALUES(14,5,'List','list','icon-list-alt',NULL);
INSERT INTO "actions" VALUES(15,5,'Create','create',' icon-plus',NULL);
INSERT INTO "actions" VALUES(16,5,'Read','read/{id}','icon-eye-open',NULL);
INSERT INTO "actions" VALUES(17,5,'Update','update/{id}','icon-edit',NULL);
INSERT INTO "actions" VALUES(18,5,'Delete','delete/{id}','icon-trash',NULL);
INSERT INTO "actions" VALUES(19,6,'List','list','icon-list-alt',NULL);
INSERT INTO "actions" VALUES(20,6,'Read','read/{id}','icon-eye-open',NULL);
INSERT INTO "actions" VALUES(21,6,'Update','update/{id}','icon-edit',NULL);
INSERT INTO "actions" VALUES(22,7,'List','list','icon-list-alt',NULL);
INSERT INTO "actions" VALUES(23,7,'Create','create',' icon-plus',NULL);
INSERT INTO "actions" VALUES(24,7,'Read','read/{id}','icon-eye-open',NULL);
INSERT INTO "actions" VALUES(25,7,'Update','update/{id}','icon-edit',NULL);
INSERT INTO "actions" VALUES(26,7,'Delete','delete/{id}','icon-trash',NULL);
INSERT INTO "actions" VALUES(27,8,'List','list','icon-list-alt',NULL);
INSERT INTO "actions" VALUES(28,8,'Create','create',' icon-plus',NULL);
INSERT INTO "actions" VALUES(29,8,'Read','read/{id}','icon-eye-open',NULL);
INSERT INTO "actions" VALUES(30,8,'Update','update/{id}','icon-edit',NULL);
INSERT INTO "actions" VALUES(31,8,'Delete','delete/{id}','icon-trash',NULL);
INSERT INTO "actions" VALUES(32,8,'Download','download/{id}','icon-download',NULL);
INSERT INTO "profiles" VALUES(1,'Firstname','Lastname',NULL,NULL,NULL,'mail@example.com',NULL,NULL,1);
INSERT INTO "nm_action_roles" VALUES(20,2);
INSERT INTO "nm_action_roles" VALUES(21,2);
INSERT INTO "nm_user_usergroups" VALUES(1,1);"""
DELETES = """"""


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('modules',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.Text(), nullable=False),
    sa.Column('clazzpath', sa.Text(), nullable=False),
    sa.Column('label', sa.Text(), nullable=False),
    sa.Column('label_plural', sa.Text(), nullable=False),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('str_repr', sa.Text(), nullable=True),
    sa.Column('display', sa.Text(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('clazzpath'),
    sa.UniqueConstraint('name')
    )
    op.create_table('user_settings',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('settings', sa.Text(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('roles',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.Text(), nullable=False),
    sa.Column('admin', sa.Boolean(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_table('usergroups',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.Text(), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_table('actions',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('mid', sa.Integer(), nullable=True),
    sa.Column('name', sa.Text(), nullable=False),
    sa.Column('url', sa.Text(), nullable=False),
    sa.Column('icon', sa.Text(), nullable=False),
    sa.Column('description', sa.Text(), nullable=True),
    sa.ForeignKeyConstraint(['mid'], ['modules.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('users',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('login', sa.Text(), nullable=False),
    sa.Column('password', sa.Text(), nullable=False),
    sa.Column('activated', sa.Boolean(), nullable=True),
    sa.Column('activation_token', sa.Text(), nullable=True),
    sa.Column('gid', sa.Integer(), nullable=True),
    sa.Column('sid', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['gid'], ['usergroups.id'], ),
    sa.ForeignKeyConstraint(['sid'], ['user_settings.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('login')
    )
    op.create_table('nm_usergroup_roles',
    sa.Column('gid', sa.Integer(), nullable=True),
    sa.Column('rid', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['gid'], ['usergroups.id'], ),
    sa.ForeignKeyConstraint(['rid'], ['roles.id'], ),
    sa.PrimaryKeyConstraint()
    )
    op.create_table('nm_user_roles',
    sa.Column('uid', sa.Integer(), nullable=True),
    sa.Column('rid', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['rid'], ['roles.id'], ),
    sa.ForeignKeyConstraint(['uid'], ['users.id'], ),
    sa.PrimaryKeyConstraint()
    )
    op.create_table('password_reset_requests',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('uid', sa.Integer(), nullable=True),
    sa.Column('created', sa.DateTime(), nullable=True),
    sa.Column('token', sa.Text(), nullable=True),
    sa.ForeignKeyConstraint(['uid'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('nm_action_roles',
    sa.Column('aid', sa.Integer(), nullable=True),
    sa.Column('rid', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['aid'], ['actions.id'], ),
    sa.ForeignKeyConstraint(['rid'], ['roles.id'], ),
    sa.PrimaryKeyConstraint()
    )
    op.create_table('profiles',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('first_name', sa.Text(), nullable=True),
    sa.Column('last_name', sa.Text(), nullable=True),
    sa.Column('birthday', sa.Date(), nullable=True),
    sa.Column('address', sa.Text(), nullable=True),
    sa.Column('phone', sa.Text(), nullable=True),
    sa.Column('email', sa.Text(), nullable=True),
    sa.Column('web', 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(['uid'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('nm_user_usergroups',
    sa.Column('uid', sa.Integer(), nullable=True),
    sa.Column('gid', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['gid'], ['usergroups.id'], ),
    sa.ForeignKeyConstraint(['uid'], ['users.id'], ),
    sa.PrimaryKeyConstraint()
    )
    op.create_table('files',
    sa.Column('id', sa.Integer(), nullable=False),
    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(['uid'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('appointments',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('start', sa.Date(), nullable=False),
    sa.Column('end', sa.Date(), nullable=False),
    sa.Column('day', sa.Text(), nullable=True),
    sa.Column('reminder', sa.Integer(), nullable=True),
    sa.Column('email', sa.Integer(), nullable=True),
    sa.Column('title', sa.Text(), nullable=False),
    sa.Column('description', 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(['uid'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    ### end Alembic commands ###
    iter_statements(INSERTS)


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('appointments')
    op.drop_table('files')
    op.drop_table('nm_user_usergroups')
    op.drop_table('profiles')
    op.drop_table('nm_action_roles')
    op.drop_table('password_reset_requests')
    op.drop_table('nm_user_roles')
    op.drop_table('nm_usergroup_roles')
    op.drop_table('users')
    op.drop_table('actions')
    op.drop_table('usergroups')
    op.drop_table('roles')
    op.drop_table('user_settings')
    op.drop_table('modules')
    ### end Alembic commands ###
    iter_statements(DELETES)
