"""empty message

Revision ID: e648e9e1adb
Revises: 
Create Date: 2015-02-24 17:27:56.180895

"""

# revision identifiers, used by Alembic.
revision = 'e648e9e1adb'
down_revision = None
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa


def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('users',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('email', sa.String(length=255), nullable=False),
    sa.Column('secret_key', sa.String(length=255), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('email')
    )
    op.create_table('counters',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=64), nullable=False),
    sa.Column('count', sa.Integer(), nullable=False),
    sa.Column('last_modified', sa.DateTime(), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_table('sites',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.Column('description', sa.Text(), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_table('attributes',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('site_id', sa.Integer(), nullable=False),
    sa.Column('resource_name', sa.String(length=20), nullable=False),
    sa.Column('name', sa.String(length=64), nullable=False),
    sa.Column('description', sa.Text(), nullable=False),
    sa.Column('required', sa.Boolean(), nullable=False),
    sa.Column('display', sa.Boolean(), nullable=False),
    sa.Column('multi', sa.Boolean(), nullable=False),
    sa.Column('constraints', sa.Text(), nullable=True),
    sa.ForeignKeyConstraint(['site_id'], [u'sites.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_attributes_resource_name'), 'attributes', ['resource_name'], unique=False)
    op.create_index('name_idx', 'attributes', ['site_id', 'resource_name', 'name'], unique=True)
    op.create_table('devices',
    sa.Column('attributes', sa.Text(), nullable=True),
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('site_id', sa.Integer(), nullable=False),
    sa.Column('hostname', sa.String(length=255), nullable=False),
    sa.ForeignKeyConstraint(['site_id'], [u'sites.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('hostname_idx', 'devices', ['site_id', 'hostname'], unique=True)
    op.create_index(op.f('ix_devices_hostname'), 'devices', ['hostname'], unique=False)
    op.create_index(op.f('ix_devices_site_id'), 'devices', ['site_id'], unique=False)
    op.create_table('permissions',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('site_id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('permissions_flag', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['site_id'], [u'sites.id'], ondelete=u'CASCADE'),
    sa.ForeignKeyConstraint(['user_id'], [u'users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('site_user_idx', 'permissions', ['site_id', 'user_id'], unique=True)
    op.create_table('networks',
    sa.Column('attributes', sa.Text(), nullable=True),
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('site_id', sa.Integer(), nullable=False),
    sa.Column('ip_version', sa.String(length=1), nullable=False),
    sa.Column('parent_id', sa.Integer(), nullable=True),
    sa.Column('network_address', sa.VARBINARY(length=16), nullable=False),
    sa.Column('broadcast_address', sa.VARBINARY(length=16), nullable=False),
    sa.Column('prefix_length', sa.Integer(), nullable=False),
    sa.Column('is_ip', sa.Boolean(), nullable=False),
    sa.ForeignKeyConstraint(['parent_id'], [u'networks.id'], ),
    sa.ForeignKeyConstraint(['site_id'], [u'sites.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('cidr_idx', 'networks', ['site_id', 'ip_version', 'network_address', 'prefix_length'], unique=True)
    op.create_index(op.f('ix_networks_broadcast_address'), 'networks', ['broadcast_address'], unique=False)
    op.create_index(op.f('ix_networks_ip_version'), 'networks', ['ip_version'], unique=False)
    op.create_index(op.f('ix_networks_is_ip'), 'networks', ['is_ip'], unique=False)
    op.create_index(op.f('ix_networks_network_address'), 'networks', ['network_address'], unique=False)
    op.create_index(op.f('ix_networks_prefix_length'), 'networks', ['prefix_length'], unique=False)
    op.create_index(op.f('ix_networks_site_id'), 'networks', ['site_id'], unique=False)
    op.create_table('changes',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('site_id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('change_at', sa.DateTime(), nullable=False),
    sa.Column('event', sa.String(length=10), nullable=False),
    sa.Column('resource_name', sa.String(length=20), nullable=False),
    sa.Column('resource_id', sa.Integer(), nullable=False),
    sa.Column('resource', sa.Text(), nullable=False),
    sa.ForeignKeyConstraint(['site_id'], [u'sites.id'], ondelete=u'CASCADE'),
    sa.ForeignKeyConstraint(['user_id'], [u'users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_changes_resource_name'), 'changes', ['resource_name'], unique=False)
    op.create_index(op.f('ix_changes_site_id'), 'changes', ['site_id'], unique=False)
    op.create_index(op.f('ix_changes_user_id'), 'changes', ['user_id'], unique=False)
    op.create_table('network_attribute_index',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=64), nullable=False),
    sa.Column('value', sa.String(length=255), nullable=False),
    sa.Column('resource_id', sa.Integer(), nullable=False),
    sa.Column('attribute_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['attribute_id'], [u'attributes.id'], ),
    sa.ForeignKeyConstraint(['resource_id'], [u'networks.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_network_attribute_index_name'), 'network_attribute_index', ['name'], unique=False)
    op.create_index(op.f('ix_network_attribute_index_value'), 'network_attribute_index', ['value'], unique=False)
    op.create_table('device_attribute_index',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=64), nullable=False),
    sa.Column('value', sa.String(length=255), nullable=False),
    sa.Column('resource_id', sa.Integer(), nullable=False),
    sa.Column('attribute_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['attribute_id'], [u'attributes.id'], ),
    sa.ForeignKeyConstraint(['resource_id'], [u'devices.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_device_attribute_index_name'), 'device_attribute_index', ['name'], unique=False)
    op.create_index(op.f('ix_device_attribute_index_value'), 'device_attribute_index', ['value'], unique=False)
    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_device_attribute_index_value'), table_name='device_attribute_index')
    op.drop_index(op.f('ix_device_attribute_index_name'), table_name='device_attribute_index')
    op.drop_table('device_attribute_index')
    op.drop_index(op.f('ix_network_attribute_index_value'), table_name='network_attribute_index')
    op.drop_index(op.f('ix_network_attribute_index_name'), table_name='network_attribute_index')
    op.drop_table('network_attribute_index')
    op.drop_index(op.f('ix_changes_user_id'), table_name='changes')
    op.drop_index(op.f('ix_changes_site_id'), table_name='changes')
    op.drop_index(op.f('ix_changes_resource_name'), table_name='changes')
    op.drop_table('changes')
    op.drop_index(op.f('ix_networks_site_id'), table_name='networks')
    op.drop_index(op.f('ix_networks_prefix_length'), table_name='networks')
    op.drop_index(op.f('ix_networks_network_address'), table_name='networks')
    op.drop_index(op.f('ix_networks_is_ip'), table_name='networks')
    op.drop_index(op.f('ix_networks_ip_version'), table_name='networks')
    op.drop_index(op.f('ix_networks_broadcast_address'), table_name='networks')
    op.drop_index('cidr_idx', table_name='networks')
    op.drop_table('networks')
    op.drop_index('site_user_idx', table_name='permissions')
    op.drop_table('permissions')
    op.drop_index(op.f('ix_devices_site_id'), table_name='devices')
    op.drop_index(op.f('ix_devices_hostname'), table_name='devices')
    op.drop_index('hostname_idx', table_name='devices')
    op.drop_table('devices')
    op.drop_index('name_idx', table_name='attributes')
    op.drop_index(op.f('ix_attributes_resource_name'), table_name='attributes')
    op.drop_table('attributes')
    op.drop_table('sites')
    op.drop_table('counters')
    op.drop_table('users')
    ### end Alembic commands ###
