<commit_before>"""Migrate draft DOS1 briefs to draft DOS2 briefs

Revision ID: 840
Revises: 830
Create Date: 2017-02-07 15:31:50.715832

"""

# revision identifiers, used by Alembic.
revision = '840'
down_revision = '830'

from alembic import op

def upgrade():
    conn = op.get_bind()

    dos1_res = conn.execute("""
        SELECT id FROM frameworks
        WHERE name = 'Digital Outcomes and Specialists'
    """)
    dos1_framework_id = dos1_res.fetchall()[0][0]

    dos2_res = conn.execute("""
        SELECT id FROM frameworks
        WHERE name = 'Digital Outcomes and Specialists 2'
    """)

    # DOS2 framework was not created with a migration, it was created via the API. This means that when the tests run
    # and set up the test database by running the migrations, there is no DOS2 framework to query to find it's ID. The
    # following check will bail out of the migration if this is the case.
    query_results = dos2_res.fetchall()
    if not query_results:
        return

    dos2_framework_id = query_results[0][0]

    op.execute("""
        UPDATE briefs
        SET framework_id = {}
        WHERE framework_id = {} AND published_at IS NULL
    """.format(dos2_framework_id, dos1_framework_id))


def downgrade():
    # No downgrade
    pass<commit_msg>Use alembics string format handling, not pythons<commit_after>"""Migrate draft DOS1 briefs to draft DOS2 briefs

Revision ID: 840
Revises: 830
Create Date: 2017-02-07 15:31:50.715832

"""

# revision identifiers, used by Alembic.
revision = '840'
down_revision = '830'

from alembic import op
from sqlalchemy.sql import text

def upgrade():
    conn = op.get_bind()

    dos1_res = conn.execute("""
        SELECT id FROM frameworks
        WHERE name = 'Digital Outcomes and Specialists'
    """)
    dos1_framework_id = dos1_res.fetchall()[0][0]

    dos2_res = conn.execute("""
        SELECT id FROM frameworks
        WHERE name = 'Digital Outcomes and Specialists 2'
    """)

    # DOS2 framework was not created with a migration, it was created via the API. This means that when the tests run
    # and set up the test database by running the migrations, there is no DOS2 framework to query to find it's ID. The
    # following check will bail out of the migration if this is the case.
    query_results = dos2_res.fetchall()
    if not query_results:
        return

    dos2_framework_id = query_results[0][0]

    framework_ids = {
        "dos1_id": dos1_framework_id,
        "dos2_id": dos2_framework_id
    }

    conn.execute(text("""
        UPDATE briefs
        SET framework_id = :dos2_id
        WHERE framework_id = :dos1_id AND published_at IS NULL
    """), **framework_ids)


def downgrade():
    # No downgrade
    pass
{'fraction_non_alphanumeric': 0.08397506417308398, 'fraction_numerical': 0.0374037403740374, 'mean_word_length': 3.011764705882353, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '4377734', 'n_tokens_mistral': 920, 'n_tokens_neox': 818, 'n_words': 301}