"""add_request_system

Revision: 9ba67b798fa
Revises: 31b92bf6506d
Created: 2013-07-23 02:49:09.342814
"""

revision = '9ba67b798fa'
down_revision = '31b92bf6506d'

from alembic import op
from spire.schema.fields import *
from spire.mesh import SurrogateType
from sqlalchemy import (Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint,
    CheckConstraint, UniqueConstraint)
from sqlalchemy.dialects import postgresql

def upgrade():
    op.create_table('request',
        Column('id', UUIDType(), nullable=False),
        Column('name', TextType(), nullable=False),
        Column('status', EnumerationType(), nullable=False),
        Column('originator', TokenType(), nullable=False),
        Column('assignee', TokenType(), nullable=False),
        PrimaryKeyConstraint('id'),
        UniqueConstraint('name'),
    )
    op.create_table('request_slot',
        Column('id', UUIDType(), nullable=False),
        Column('request_id', UUIDType(), nullable=False),
        Column('token', TokenType(), nullable=False),
        Column('title', TextType(), nullable=True),
        Column('slot', TokenType(), nullable=False),
        ForeignKeyConstraint(['request_id'], ['request.id'], ondelete='CASCADE'),
        PrimaryKeyConstraint('id'),
        UniqueConstraint('request_id','token'),
    )
    op.create_table('request_attachment',
        Column('id', UUIDType(), nullable=False),
        Column('request_id', UUIDType(), nullable=False),
        Column('token', TokenType(), nullable=True),
        Column('title', TextType(), nullable=True),
        Column('attachment', SurrogateType(), nullable=False),
        ForeignKeyConstraint(['request_id'], ['request.id'], ondelete='CASCADE'),
        PrimaryKeyConstraint('id'),
    )
    op.create_table('request_product',
        Column('id', UUIDType(), nullable=False),
        Column('request_id', UUIDType(), nullable=False),
        Column('token', TokenType(), nullable=False),
        Column('title', TextType(), nullable=True),
        Column('product', SurrogateType(), nullable=False),
        ForeignKeyConstraint(['request_id'], ['request.id'], ondelete='CASCADE'),
        PrimaryKeyConstraint('id'),
        UniqueConstraint('request_id','token'),
    )
    op.create_table('message',
        Column('id', UUIDType(), nullable=False),
        Column('request_id', UUIDType(), nullable=False),
        Column('author', TokenType(), nullable=False),
        Column('occurrence', DateTimeType(timezone=True), nullable=False),
        Column('message', TextType(), nullable=True),
        ForeignKeyConstraint(['request_id'], ['request.id'], ondelete='CASCADE'),
        PrimaryKeyConstraint('id'),
    )

def downgrade():
    op.drop_table('message')
    op.drop_table('request_product')
    op.drop_table('request_attachment')
    op.drop_table('request_slot')
    op.drop_table('request')

[((2702, 2726), 'alembic.op.drop_table', 'op.drop_table', (['"""message"""'], {}), "('message')\n", (2715, 2726), False, 'from alembic import op\n'), ((2731, 2763), 'alembic.op.drop_table', 'op.drop_table', (['"""request_product"""'], {}), "('request_product')\n", (2744, 2763), False, 'from alembic import op\n'), ((2768, 2803), 'alembic.op.drop_table', 'op.drop_table', (['"""request_attachment"""'], {}), "('request_attachment')\n", (2781, 2803), False, 'from alembic import op\n'), ((2808, 2837), 'alembic.op.drop_table', 'op.drop_table', (['"""request_slot"""'], {}), "('request_slot')\n", (2821, 2837), False, 'from alembic import op\n'), ((2842, 2866), 'alembic.op.drop_table', 'op.drop_table', (['"""request"""'], {}), "('request')\n", (2855, 2866), False, 'from alembic import op\n'), ((763, 789), 'sqlalchemy.PrimaryKeyConstraint', 'PrimaryKeyConstraint', (['"""id"""'], {}), "('id')\n", (783, 789), False, 'from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, CheckConstraint, UniqueConstraint\n'), ((799, 823), 'sqlalchemy.UniqueConstraint', 'UniqueConstraint', (['"""name"""'], {}), "('name')\n", (815, 823), False, 'from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, CheckConstraint, UniqueConstraint\n'), ((1142, 1214), 'sqlalchemy.ForeignKeyConstraint', 'ForeignKeyConstraint', (["['request_id']", "['request.id']"], {'ondelete': '"""CASCADE"""'}), "(['request_id'], ['request.id'], ondelete='CASCADE')\n", (1162, 1214), False, 'from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, CheckConstraint, UniqueConstraint\n'), ((1224, 1250), 'sqlalchemy.PrimaryKeyConstraint', 'PrimaryKeyConstraint', (['"""id"""'], {}), "('id')\n", (1244, 1250), False, 'from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, CheckConstraint, UniqueConstraint\n'), ((1260, 1299), 'sqlalchemy.UniqueConstraint', 'UniqueConstraint', (['"""request_id"""', '"""token"""'], {}), "('request_id', 'token')\n", (1276, 1299), False, 'from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, CheckConstraint, UniqueConstraint\n'), ((1632, 1704), 'sqlalchemy.ForeignKeyConstraint', 'ForeignKeyConstraint', (["['request_id']", "['request.id']"], {'ondelete': '"""CASCADE"""'}), "(['request_id'], ['request.id'], ondelete='CASCADE')\n", (1652, 1704), False, 'from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, CheckConstraint, UniqueConstraint\n'), ((1714, 1740), 'sqlalchemy.PrimaryKeyConstraint', 'PrimaryKeyConstraint', (['"""id"""'], {}), "('id')\n", (1734, 1740), False, 'from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, CheckConstraint, UniqueConstraint\n'), ((2069, 2141), 'sqlalchemy.ForeignKeyConstraint', 'ForeignKeyConstraint', (["['request_id']", "['request.id']"], {'ondelete': '"""CASCADE"""'}), "(['request_id'], ['request.id'], ondelete='CASCADE')\n", (2089, 2141), False, 'from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, CheckConstraint, UniqueConstraint\n'), ((2151, 2177), 'sqlalchemy.PrimaryKeyConstraint', 'PrimaryKeyConstraint', (['"""id"""'], {}), "('id')\n", (2171, 2177), False, 'from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, CheckConstraint, UniqueConstraint\n'), ((2187, 2226), 'sqlalchemy.UniqueConstraint', 'UniqueConstraint', (['"""request_id"""', '"""token"""'], {}), "('request_id', 'token')\n", (2203, 2226), False, 'from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, CheckConstraint, UniqueConstraint\n'), ((2564, 2636), 'sqlalchemy.ForeignKeyConstraint', 'ForeignKeyConstraint', (["['request_id']", "['request.id']"], {'ondelete': '"""CASCADE"""'}), "(['request_id'], ['request.id'], ondelete='CASCADE')\n", (2584, 2636), False, 'from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, CheckConstraint, UniqueConstraint\n'), ((2646, 2672), 'sqlalchemy.PrimaryKeyConstraint', 'PrimaryKeyConstraint', (['"""id"""'], {}), "('id')\n", (2666, 2672), False, 'from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, CheckConstraint, UniqueConstraint\n'), ((1590, 1605), 'spire.mesh.SurrogateType', 'SurrogateType', ([], {}), '()\n', (1603, 1605), False, 'from spire.mesh import SurrogateType\n'), ((2027, 2042), 'spire.mesh.SurrogateType', 'SurrogateType', ([], {}), '()\n', (2040, 2042), False, 'from spire.mesh import SurrogateType\n')]