"""Added PageBanner mapped class.

Revision ID: 2c0bfc379e01
Revises: 2637e08f3c15
Create Date: 2012-04-02 14:24:16.271417

"""

# downgrade revision identifier, used by Alembic.
revision = '2c0bfc379e01'
down_revision = '18da1d3c685a'

from alembic import op
import sqlalchemy as sa


def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    # create instance_groups table
    op.create_table(u'_pagebanner_secondary_tmp',
                    sa.Column('files_id',
                              sa.Integer,
                              sa.ForeignKey('files.id',
                                            onupdate='cascade',
                                            ondelete='cascade'),
                              primary_key=True),
                    sa.Column('nodes_id',
                              sa.Integer,
                              sa.ForeignKey('nodes.id',
                                            onupdate='cascade',
                                            ondelete='cascade'),
                              primary_key=True),
                    sa.Column(u'weight',
                              sa.Integer,
                              default=0),
                    mysql_engine=u'InnoDB')
    # populate instances_groups
    connection = op.get_bind()
    connection.execute(
        'INSERT INTO _pagebanner_secondary_tmp (nodes_id, files_id) '
        'SELECT nodes_id, files_id '
        'FROM nodes_banners__files'
    )
    op.drop_table(u'nodes_banners__files')
    op.rename_table(u'_pagebanner_secondary_tmp', u'nodes_banners__files')
    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table(u'_pagebanner_secondary_tmp',
                    sa.Column('files_id',
                              sa.Integer,
                              sa.ForeignKey('files.id',
                                            onupdate='cascade',
                                            ondelete='cascade')),
                    sa.Column('nodes_id',
                              sa.Integer,
                              sa.ForeignKey('nodes.id',
                                            onupdate='cascade',
                                            ondelete='cascade')),
                    mysql_engine=u'InnoDB')
    # populate instances_groups
    connection = op.get_bind()
    connection.execute(
        'INSERT INTO _pagebanner_secondary_tmp (nodes_id, files_id) '
        'SELECT nodes_id, files_id '
        'FROM nodes_banners__files'
    )
    op.drop_table(u'nodes_banners__files')
    op.rename_table(u'_pagebanner_secondary_tmp', u'nodes_banners__files')
    ### end Alembic commands ###
