"""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')

[((68, 4, 68, 28), 'alembic.op.drop_table', 'op.drop_table', ({(68, 18, 68, 27): '"""message"""'}, {}), "('message')", False, 'from alembic import op\n'), ((69, 4, 69, 36), 'alembic.op.drop_table', 'op.drop_table', ({(69, 18, 69, 35): '"""request_product"""'}, {}), "('request_product')", False, 'from alembic import op\n'), ((70, 4, 70, 39), 'alembic.op.drop_table', 'op.drop_table', ({(70, 18, 70, 38): '"""request_attachment"""'}, {}), "('request_attachment')", False, 'from alembic import op\n'), ((71, 4, 71, 33), 'alembic.op.drop_table', 'op.drop_table', ({(71, 18, 71, 32): '"""request_slot"""'}, {}), "('request_slot')", False, 'from alembic import op\n'), ((72, 4, 72, 28), 'alembic.op.drop_table', 'op.drop_table', ({(72, 18, 72, 27): '"""request"""'}, {}), "('request')", False, 'from alembic import op\n'), ((25, 8, 25, 34), 'sqlalchemy.PrimaryKeyConstraint', 'PrimaryKeyConstraint', ({(25, 29, 25, 33): '"""id"""'}, {}), "('id')", False, 'from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, CheckConstraint, UniqueConstraint\n'), ((26, 8, 26, 32), 'sqlalchemy.UniqueConstraint', 'UniqueConstraint', ({(26, 25, 26, 31): '"""name"""'}, {}), "('name')", False, 'from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, CheckConstraint, UniqueConstraint\n'), ((34, 8, 34, 80), 'sqlalchemy.ForeignKeyConstraint', 'ForeignKeyConstraint', (), '', False, 'from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, CheckConstraint, UniqueConstraint\n'), ((35, 8, 35, 34), 'sqlalchemy.PrimaryKeyConstraint', 'PrimaryKeyConstraint', ({(35, 29, 35, 33): '"""id"""'}, {}), "('id')", False, 'from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, CheckConstraint, UniqueConstraint\n'), ((36, 8, 36, 46), 'sqlalchemy.UniqueConstraint', 'UniqueConstraint', ({(36, 25, 36, 37): '"""request_id"""', (36, 38, 36, 45): '"""token"""'}, {}), "('request_id', 'token')", False, 'from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, CheckConstraint, UniqueConstraint\n'), ((44, 8, 44, 80), 'sqlalchemy.ForeignKeyConstraint', 'ForeignKeyConstraint', (), '', False, 'from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, CheckConstraint, UniqueConstraint\n'), ((45, 8, 45, 34), 'sqlalchemy.PrimaryKeyConstraint', 'PrimaryKeyConstraint', ({(45, 29, 45, 33): '"""id"""'}, {}), "('id')", False, 'from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, CheckConstraint, UniqueConstraint\n'), ((53, 8, 53, 80), 'sqlalchemy.ForeignKeyConstraint', 'ForeignKeyConstraint', (), '', False, 'from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, CheckConstraint, UniqueConstraint\n'), ((54, 8, 54, 34), 'sqlalchemy.PrimaryKeyConstraint', 'PrimaryKeyConstraint', ({(54, 29, 54, 33): '"""id"""'}, {}), "('id')", False, 'from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, CheckConstraint, UniqueConstraint\n'), ((55, 8, 55, 46), 'sqlalchemy.UniqueConstraint', 'UniqueConstraint', ({(55, 25, 55, 37): '"""request_id"""', (55, 38, 55, 45): '"""token"""'}, {}), "('request_id', 'token')", False, 'from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, CheckConstraint, UniqueConstraint\n'), ((63, 8, 63, 80), 'sqlalchemy.ForeignKeyConstraint', 'ForeignKeyConstraint', (), '', False, 'from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, CheckConstraint, UniqueConstraint\n'), ((64, 8, 64, 34), 'sqlalchemy.PrimaryKeyConstraint', 'PrimaryKeyConstraint', ({(64, 29, 64, 33): '"""id"""'}, {}), "('id')", False, 'from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, CheckConstraint, UniqueConstraint\n'), ((43, 29, 43, 44), 'spire.mesh.SurrogateType', 'SurrogateType', ({}, {}), '()', False, 'from spire.mesh import SurrogateType\n'), ((52, 26, 52, 41), 'spire.mesh.SurrogateType', 'SurrogateType', ({}, {}), '()', False, 'from spire.mesh import SurrogateType\n')]