"""Add plugin tables

Revision ID: 7c3fcf8a3335
Revises:
Create Date: 2017-11-18 09:53

"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = '7c3fcf8a3335'
down_revision = 'd0ffadc3ea48'
branch_labels = ()
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'plugin_registry',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.Unicode(length=255), nullable=False),
        sa.Column('enabled', sa.Boolean(), nullable=True),
        sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name')
    )

    op.create_table(
        'plugin_store',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('key', sa.Unicode(length=255), nullable=False),
        sa.Column('value', sa.PickleType(), nullable=False),
        sa.Column('value_type', sa.Enum(
            'string', 'integer', 'float', 'boolean', 'select', 'selectmultiple',
            name='settingvaluetype'), nullable=False
        ),
        sa.Column('extra', sa.PickleType(), nullable=True),
        sa.Column('plugin_id', sa.Integer(), nullable=True),
        sa.Column('name', sa.Unicode(length=255), nullable=False),
        sa.Column('description', sa.Text(), nullable=True),
        sa.ForeignKeyConstraint(
            ['plugin_id'],
            ['plugin_registry.id'],
        ),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('key', 'plugin_id', name='plugin_kv_uniq')
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('plugin_store')
    op.drop_table('plugin_registry')
    # ### end Alembic commands ###
