<commit_before>"""Add registration tables

Revision ID: f9bb2a03ceb
Revises: <PASSWORD>
Create Date: 2015-09-04 15:15:03.682231
"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
from sqlalchemy.sql.ddl import CreateSchema, DropSchema

from indico.core.db.sqlalchemy import PyIntEnum, UTCDateTime
from indico.modules.events.registration.models.registration_forms import RegistrationFormModificationMode


# revision identifiers, used by Alembic.
revision = 'f9bb2a03ceb'
down_revision = '<PASSWORD>'


def upgrade():
    op.execute(CreateSchema('event_registration'))
    op.create_table(
        'registration_forms',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('event_id', sa.Integer(), nullable=False, index=True),
        sa.Column('title', sa.String(), nullable=False),
        sa.Column('introduction', sa.Text(), nullable=False),
        sa.Column('start_dt', UTCDateTime, nullable=True),
        sa.Column('end_dt', UTCDateTime, nullable=True),
        sa.Column('modification_mode', PyIntEnum(RegistrationFormModificationMode), nullable=False),
        sa.Column('modification_end_dt', UTCDateTime, nullable=True),
        sa.Column('is_deleted', sa.Boolean(), nullable=False),
        sa.Column('require_user', sa.Boolean(), nullable=False),
        sa.Column('registration_limit', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(['event_id'], ['events.events.id']),
        sa.PrimaryKeyConstraint('id'),
        schema='event_registration'
    )

    op.create_table(
        'registration_form_items',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('registration_form_id', sa.Integer(), nullable=False),
        sa.Column('type', sa.Integer(), nullable=False),
        sa.Column('parent_id', sa.Integer(), nullable=True),
        sa.Column('position', sa.Integer(), nullable=False),
        sa.Column('title', sa.String(), nullable=False),
        sa.Column('description', sa.String(), nullable=True),
        sa.Column('is_enabled', sa.Boolean(), nullable=True),
        sa.Column('is_deleted', sa.Boolean(), nullable=True),
        sa.Column('current_data_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(['parent_id'], ['event_registration.registration_form_items.id']),
        sa.ForeignKeyConstraint(['registration_form_id'], ['event_registration.registration_forms.id']),
        sa.PrimaryKeyConstraint('id'),
        schema='event_registration'
    )

    op.create_table(
        'registration_form_field_data',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('field_id', sa.Integer(), nullable=False),
        sa.Column('data', postgresql.JSON(), nullable=False),
        sa.ForeignKeyConstraint(['field_id'], ['event_registration.registration_form_items.id']),
        sa.PrimaryKeyConstraint('id'),
        schema='event_registration'
    )

    op.create_foreign_key(None,
                          'registration_form_items', 'registration_form_field_data',
                          ['current_data_id'], ['id'],
                          source_schema='event_registration', referent_schema='event_registration')

    op.create_table(
        'registrations',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('registration_form_id', sa.Integer(), nullable=False, index=True),
        sa.Column('user_id', sa.Integer(), nullable=True, index=True),
        sa.Column('submitted_dt', UTCDateTime, nullable=False),
        sa.ForeignKeyConstraint(['registration_form_id'], ['event_registration.registration_forms.id']),
        sa.ForeignKeyConstraint(['user_id'], ['users.users.id']),
        sa.PrimaryKeyConstraint('id'),
        schema='event_registration'
    )

    op.create_table(
        'registration_data',
        sa.Column('registration_id', sa.Integer(), nullable=False),
        sa.Column('field_data_id', sa.Integer(), nullable=False),
        sa.Column('data', postgresql.JSON(), nullable=False),
        sa.Column('file', sa.LargeBinary(), nullable=True),
        sa.Column('file_metadata', postgresql.JSON(), nullable=False),
        sa.CheckConstraint("(file IS NULL) = (file_metadata::text = 'null')", name='valid_file'),
        sa.ForeignKeyConstraint(['field_data_id'], ['event_registration.registration_form_field_data.id']),
        sa.ForeignKeyConstraint(['registration_id'], ['event_registration.registrations.id']),
        sa.PrimaryKeyConstraint('registration_id', 'field_data_id'),
        schema='event_registration'
    )


def downgrade():
    op.drop_column('registration_form_items', 'current_data_id', schema='event_registration')
    op.drop_table('registration_data', schema='event_registration')
    op.drop_table('registrations', schema='event_registration')
    op.drop_table('registration_form_field_data', schema='event_registration')
    op.drop_table('registration_form_items', schema='event_registration')
    op.drop_table('registration_forms', schema='event_registration')
    op.execute(DropSchema('event_registration'))<commit_msg>Drop foreign key instead of dropping the column<commit_after>"""Add registration tables

Revision ID: f9bb2a03ceb
Revises: <PASSWORD>
Create Date: 2015-09-04 15:15:03.682231
"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
from sqlalchemy.sql.ddl import CreateSchema, DropSchema

from indico.core.db.sqlalchemy import PyIntEnum, UTCDateTime
from indico.modules.events.registration.models.registration_forms import RegistrationFormModificationMode


# revision identifiers, used by Alembic.
revision = 'f9bb2a03ceb'
down_revision = '<PASSWORD>'


def upgrade():
    op.execute(CreateSchema('event_registration'))
    op.create_table(
        'registration_forms',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('event_id', sa.Integer(), nullable=False, index=True),
        sa.Column('title', sa.String(), nullable=False),
        sa.Column('introduction', sa.Text(), nullable=False),
        sa.Column('start_dt', UTCDateTime, nullable=True),
        sa.Column('end_dt', UTCDateTime, nullable=True),
        sa.Column('modification_mode', PyIntEnum(RegistrationFormModificationMode), nullable=False),
        sa.Column('modification_end_dt', UTCDateTime, nullable=True),
        sa.Column('is_deleted', sa.Boolean(), nullable=False),
        sa.Column('require_user', sa.Boolean(), nullable=False),
        sa.Column('registration_limit', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(['event_id'], ['events.events.id']),
        sa.PrimaryKeyConstraint('id'),
        schema='event_registration'
    )

    op.create_table(
        'registration_form_items',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('registration_form_id', sa.Integer(), nullable=False),
        sa.Column('type', sa.Integer(), nullable=False),
        sa.Column('parent_id', sa.Integer(), nullable=True),
        sa.Column('position', sa.Integer(), nullable=False),
        sa.Column('title', sa.String(), nullable=False),
        sa.Column('description', sa.String(), nullable=True),
        sa.Column('is_enabled', sa.Boolean(), nullable=True),
        sa.Column('is_deleted', sa.Boolean(), nullable=True),
        sa.Column('current_data_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(['parent_id'], ['event_registration.registration_form_items.id']),
        sa.ForeignKeyConstraint(['registration_form_id'], ['event_registration.registration_forms.id']),
        sa.PrimaryKeyConstraint('id'),
        schema='event_registration'
    )

    op.create_table(
        'registration_form_field_data',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('field_id', sa.Integer(), nullable=False),
        sa.Column('data', postgresql.JSON(), nullable=False),
        sa.ForeignKeyConstraint(['field_id'], ['event_registration.registration_form_items.id']),
        sa.PrimaryKeyConstraint('id'),
        schema='event_registration'
    )

    op.create_foreign_key(None,
                          'registration_form_items', 'registration_form_field_data',
                          ['current_data_id'], ['id'],
                          source_schema='event_registration', referent_schema='event_registration')

    op.create_table(
        'registrations',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('registration_form_id', sa.Integer(), nullable=False, index=True),
        sa.Column('user_id', sa.Integer(), nullable=True, index=True),
        sa.Column('submitted_dt', UTCDateTime, nullable=False),
        sa.ForeignKeyConstraint(['registration_form_id'], ['event_registration.registration_forms.id']),
        sa.ForeignKeyConstraint(['user_id'], ['users.users.id']),
        sa.PrimaryKeyConstraint('id'),
        schema='event_registration'
    )

    op.create_table(
        'registration_data',
        sa.Column('registration_id', sa.Integer(), nullable=False),
        sa.Column('field_data_id', sa.Integer(), nullable=False),
        sa.Column('data', postgresql.JSON(), nullable=False),
        sa.Column('file', sa.LargeBinary(), nullable=True),
        sa.Column('file_metadata', postgresql.JSON(), nullable=False),
        sa.CheckConstraint("(file IS NULL) = (file_metadata::text = 'null')", name='valid_file'),
        sa.ForeignKeyConstraint(['field_data_id'], ['event_registration.registration_form_field_data.id']),
        sa.ForeignKeyConstraint(['registration_id'], ['event_registration.registrations.id']),
        sa.PrimaryKeyConstraint('registration_id', 'field_data_id'),
        schema='event_registration'
    )


def downgrade():
    op.drop_constraint('fk_registration_form_items_current_data_id_registration_form_field_data',
                       'registration_form_items', schema='event_registration')
    op.drop_table('registration_data', schema='event_registration')
    op.drop_table('registrations', schema='event_registration')
    op.drop_table('registration_form_field_data', schema='event_registration')
    op.drop_table('registration_form_items', schema='event_registration')
    op.drop_table('registration_forms', schema='event_registration')
    op.execute(DropSchema('event_registration'))
{'fraction_non_alphanumeric': 0.14653580798756194, 'fraction_numerical': 0.005441648041978428, 'mean_word_length': 4.211139240506329, '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': '534628', 'n_tokens_mistral': 3104, 'n_tokens_neox': 2975, 'n_words': 442}