<commit_before>"""mark obmd fields not nullable

Revision ID: d65a9dc873d7
Revises: <PASSWORD>
Create Date: 2018-04-07 19:10:35.243712

"""

import os
from alembic import op
import sqlalchemy as sa
from sqlalchemy.orm import Session
from hil import model


# revision identifiers, used by Alembic.
revision = 'd65a9dc873d7'
down_revision = '2<PASSWORD>'
branch_labels = ('hil',)

# pylint: disable=missing-docstring


def upgrade():
    if os.getenv('SPOOF_MANUAL_MIGRATIONS') == 'true':
        # The normal upgrade process requires an admin to run a helper
        # script that we've written, which exports node info to OBMd,
        # and adds the relevant fields. In the test suite, we don't have
        # the opportunity to do this, so we expose (via an environment
        # variable) the ability to spoof the data, so that the tests can
        # pass.
        conn = op.get_bind()
        session = Session(bind=conn)
        for node in session.query(model.Node):
            # If we're in the test, we should expect that neither of these
            # has been set:
            assert node.obmd_uri is None
            assert node.obmd_admin_token is None

            node.obmd_uri = 'http://obmd.example.com/nodes/' + node.label
            node.obmd_admin_token = '<PASSWORD>'

    op.alter_column('node', 'obmd_admin_token',
               existing_type=sa.VARCHAR(),
               nullable=False)
    op.alter_column('node', 'obmd_uri',
               existing_type=sa.VARCHAR(),
               nullable=False)


def downgrade():
    op.alter_column('node', 'obmd_uri',
               existing_type=sa.VARCHAR(),
               nullable=True)
    op.alter_column('node', 'obmd_admin_token',
               existing_type=sa.VARCHAR(),
               nullable=True)<commit_msg>Fix style issues in migration script.<commit_after>"""mark obmd fields not nullable

Revision ID: d65a9dc873d7
Revises: 2<PASSWORD>
Create Date: 2018-04-07 19:10:35.243712

"""

import os
from alembic import op
import sqlalchemy as sa
from sqlalchemy.orm import Session
from hil import model


# revision identifiers, used by Alembic.
revision = 'd65a9dc873d7'
down_revision = '2<PASSWORD>'
branch_labels = ('hil',)

# pylint: disable=missing-docstring


def upgrade():
    if os.getenv('SPOOF_MANUAL_MIGRATIONS') == 'true':
        # The normal upgrade process requires an admin to run a helper
        # script that we've written, which exports node info to OBMd,
        # and adds the relevant fields. In the test suite, we don't have
        # the opportunity to do this, so we expose (via an environment
        # variable) the ability to spoof the data, so that the tests can
        # pass.
        conn = op.get_bind()
        session = Session(bind=conn)
        for node in session.query(model.Node):
            # If we're in the test, we should expect that neither of these
            # has been set:
            assert node.obmd_uri is None
            assert node.obmd_admin_token is None

            node.obmd_uri = 'http://obmd.example.com/nodes/' + node.label
            node.obmd_admin_token = '<PASSWORD>'

    op.alter_column(
        'node',
        'obmd_admin_token',
        existing_type=sa.VARCHAR(),
        nullable=False,
    )
    op.alter_column(
        'node',
        'obmd_uri',
        existing_type=sa.VARCHAR(),
        nullable=False,
    )


def downgrade():
    op.alter_column(
        'node',
        'obmd_uri',
        existing_type=sa.VARCHAR(),
        nullable=True,
    )
    op.alter_column(
        'node',
        'obmd_admin_token',
        existing_type=sa.VARCHAR(),
        nullable=True,
    )
{'fraction_non_alphanumeric': 0.0962434877981903, 'fraction_numerical': 0.01946805593638607, 'mean_word_length': 2.4643874643874644, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5107991', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1109, 'n_words': 330}