<commit_before>"""add session types table

Revision ID: 9c4418d7a6aa
Revises: <PASSWORD>
Create Date: 2017-12-14 10:59:47.872426
"""

import sqlalchemy as sa
from alembic import op


# revision identifiers, used by Alembic.
revision = '<KEY>'
down_revision = '<PASSWORD>'
branch_labels = None
depends_on = None


def upgrade():
    # Create session type table
    op.create_table('session_types',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('event_id', sa.Integer(), nullable=False, index=True),
                    sa.Column('name', sa.String(), nullable=False),
                    sa.Column('is_poster', sa.Boolean(), nullable=False),
                    sa.ForeignKeyConstraint(['event_id'], ['events.events.id']),
                    sa.PrimaryKeyConstraint('id'),
                    schema='events')
    op.create_index('ix_uq_session_types_event_id_name_lower', 'session_types', ['event_id', sa.text('lower(name)')],
                    unique=True, schema='events')

    # Add session type to sessions
    op.add_column('sessions', sa.Column('type_id', sa.Integer(), nullable=True), schema='events')
    op.create_index(None, 'sessions', ['type_id'], unique=False, schema='events')
    op.create_foreign_key(None, 'sessions', 'session_types', ['type_id'], ['id'], source_schema='events',
                          referent_schema='events')

    # Migrate poster sessions to sessions with poster session type
    op.execute('''
      INSERT INTO events.session_types (event_id, name, is_poster)
      SELECT event_id, 'Poster session', true
      FROM events.sessions
      WHERE is_poster
      GROUP BY event_id;
      <commit_msg>Update session types migration<commit_after>"""Add session types table

Revision ID: 9c4418d7a6aa
Revises: 2af245be72a6
Create Date: 2017-12-14 10:59:47.872426
"""

import sqlalchemy as sa
from alembic import op


# revision identifiers, used by Alembic.
revision = '<KEY>'
down_revision = '2af245be72a6'
branch_labels = None
depends_on = None


def upgrade():
    # Create session type table
    op.create_table('session_types',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('event_id', sa.Integer(), nullable=False, index=True),
                    sa.Column('name', sa.String(), nullable=False),
                    sa.Column('is_poster', sa.Boolean(), nullable=False),
                    sa.ForeignKeyConstraint(['event_id'], ['events.events.id']),
                    sa.PrimaryKeyConstraint('id'),
                    schema='events')
    op.create_index('ix_uq_session_types_event_id_name_lower', 'session_types', ['event_id', sa.text('lower(name)')],
                    unique=True, schema='events')

    # Add session type to sessions
    op.add_column('sessions', sa.Column('type_id', sa.Integer(), nullable=True), schema='events')
    op.create_index(None, 'sessions', ['type_id'], unique=False, schema='events')
    op.create_foreign_key(None, 'sessions', 'session_types', ['type_id'], ['id'], source_schema='events',
                          referent_schema='events')

    # Migrate poster sessions to sessions with poster session type
    op.execute('''
      INSERT INTO events.session_types (event_id, name, is_poster)
      SELECT event_id, 'Poster session', true
      FROM events.sessions
      WHERE is_poster
      GROUP BY event_id;
      
{'fraction_non_alphanumeric': 0.13259020240539748, 'fraction_numerical': 0.01994719859196245, 'mean_word_length': 3.0789473684210527, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4673276', 'n_tokens_mistral': 1085, 'n_tokens_neox': 999, 'n_words': 231}