migrations/versions/3c78152eb874_first_migration.py
changeset 78 37bb8e326446
equal deleted inserted replaced
77:1b578edc1578 78:37bb8e326446
       
     1 """First migration
       
     2 
       
     3 Revision ID: 3c78152eb874
       
     4 Revises: None
       
     5 Create Date: 2014-10-28 15:24:25.401385
       
     6 
       
     7 """
       
     8 
       
     9 # revision identifiers, used by Alembic.
       
    10 revision = '3c78152eb874'
       
    11 down_revision = None
       
    12 
       
    13 from alembic import op
       
    14 import sqlalchemy as sa
       
    15 from sqlalchemy.dialects import postgresql
       
    16 
       
    17 def upgrade():
       
    18     op.create_table('event',
       
    19     sa.Column('id', sa.Integer(), nullable=False),
       
    20     sa.Column('code', sa.String(length=255), nullable=False),
       
    21     sa.Column('label', sa.String(length=2048), nullable=False),
       
    22     sa.Column('description', sa.Text(), nullable=True),
       
    23     sa.Column('start_date', sa.DateTime(), nullable=True),
       
    24     sa.Column('active', sa.Boolean(), server_default='1', nullable=False),
       
    25     sa.PrimaryKeyConstraint('id')
       
    26     )
       
    27     op.create_index(op.f('ix_event_active'), 'event', ['active'], unique=False)
       
    28     op.create_index(op.f('ix_event_code'), 'event', ['code'], unique=True)
       
    29     op.create_index(op.f('ix_event_start_date'), 'event', ['start_date'], unique=False)
       
    30     op.create_table('event_session',
       
    31     sa.Column('id', sa.Integer(), nullable=False),
       
    32     sa.Column('event_id', sa.Integer(), nullable=False),
       
    33     sa.Column('project_id', sa.String(length=2048), nullable=True),
       
    34     sa.Column('order', sa.Integer(), nullable=False),
       
    35     sa.Column('start_ts', sa.DateTime(timezone=True), nullable=True),
       
    36     sa.Column('duration', sa.Integer(), nullable=True),
       
    37     sa.Column('categories_json', postgresql.JSON(), nullable=True),
       
    38     sa.ForeignKeyConstraint(['event_id'], [u'event.id'], ),
       
    39     sa.PrimaryKeyConstraint('id')
       
    40     )
       
    41     op.create_index(op.f('ix_event_session_order'), 'event_session', ['order'], unique=False)
       
    42     op.create_index(op.f('ix_event_session_start_ts'), 'event_session', ['start_ts'], unique=False)
       
    43     op.create_table('annotation',
       
    44     sa.Column('id', sa.Integer(), nullable=False),
       
    45     sa.Column('uuid', postgresql.UUID(), nullable=False),
       
    46     sa.Column('created', sa.DateTime(), server_default=sa.text("(now() at time zone 'utc')"), nullable=False),
       
    47     sa.Column('ts', sa.DateTime(timezone=True), nullable=False),
       
    48     sa.Column('event_code', sa.String(length=255), nullable=False),
       
    49     sa.Column('channel', sa.String(length=255), nullable=False),
       
    50     sa.Column('content', postgresql.JSON(), nullable=True),
       
    51     sa.ForeignKeyConstraint(['event_code'], ['event.code'], ),
       
    52     sa.PrimaryKeyConstraint('id'),
       
    53     sa.UniqueConstraint('uuid')
       
    54     )
       
    55     op.create_index(op.f('ix_annotation_channel'), 'annotation', ['channel'], unique=False)
       
    56     op.create_index(op.f('ix_annotation_event_code'), 'annotation', ['event_code'], unique=False)
       
    57     op.create_index(op.f('ix_annotation_ts'), 'annotation', ['ts'], unique=False)
       
    58 
       
    59 
       
    60 def downgrade():
       
    61     op.drop_index(op.f('ix_annotation_ts'), table_name='annotation')
       
    62     op.drop_index(op.f('ix_annotation_event_code'), table_name='annotation')
       
    63     op.drop_index(op.f('ix_annotation_channel'), table_name='annotation')
       
    64     op.drop_table('annotation')
       
    65     op.drop_index(op.f('ix_event_session_start_ts'), table_name='event_session')
       
    66     op.drop_index(op.f('ix_event_session_order'), table_name='event_session')
       
    67     op.drop_table('event_session')
       
    68     op.drop_index(op.f('ix_event_start_date'), table_name='event')
       
    69     op.drop_index(op.f('ix_event_code'), table_name='event')
       
    70     op.drop_index(op.f('ix_event_active'), table_name='event')
       
    71     op.drop_table('event')