<commit_before>from alembic import op
import sqlalchemy as sa
from sqlalchemy.orm import sessionmaker, make_transient

from portal.models.organization import Organization, UserOrganization, OrganizationLocale
from portal.models.organization import OrganizationIdentifier, OrganizationAddress, OrgTree
from portal.models.questionnaire_bank import QuestionnaireBank
from portal.models.tou import ToU
from portal.models.user_consent import UserConsent

"""empty message

Revision ID: b814b51681bf
Revises: <KEY>
Create Date: 2017-10-13 14:48:52.190149

"""

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

Session = sessionmaker()

def update_org_id(old_id, new_id, new_parent_id=None, new_name=None):
    bind = op.get_bind()
    session = Session(bind=bind)

    org = session.query(Organization).get(old_id)
    if not org:
        return
    OT = OrgTree()
    if len(OT.here_and_below_id(old_id)) > 1:
        raise ValueError('organization `{}` cannot be moved '
                         'before children'.format(old_id))

    make_transient(org)

    org.id = new_id
    if new_parent_id:
        org.partOf_id = new_parent_id
    if new_name:
        org.name = new_name
    session.add(org)
    session.commit()<commit_msg>my name is pep8 montoya. you killed my father. prepare to die.<commit_after>from alembic import op
import sqlalchemy as sa
from sqlalchemy.orm import sessionmaker, make_transient

from portal.models.organization import Organization, UserOrganization, OrganizationLocale
from portal.models.organization import OrganizationIdentifier, OrganizationAddress, OrgTree
from portal.models.questionnaire_bank import QuestionnaireBank
from portal.models.tou import ToU
from portal.models.user_consent import UserConsent

"""empty message

Revision ID: b814b51681bf
Revises: <KEY>
Create Date: 2017-10-13 14:48:52.190149

"""

# revision identifiers, used by Alembic.
revision = 'b814b51681bf'
down_revision = '<KEY>'

Session = sessionmaker()


def update_org_id(old_id, new_id, new_parent_id=None, new_name=None):
    bind = op.get_bind()
    session = Session(bind=bind)

    org = session.query(Organization).get(old_id)
    if not org:
        return
    OT = OrgTree()
    if len(OT.here_and_below_id(old_id)) > 1:
        raise ValueError('organization `{}` cannot be moved '
                         'before children'.format(old_id))

    make_transient(org)

    org.id = new_id
    if new_parent_id:
        org.partOf_id = new_parent_id
    if new_name:
        org.name = new_name
    session.add(org)
    session.commit()
{'fraction_non_alphanumeric': 0.0884511394360757, 'fraction_numerical': 0.025878717651602934, 'mean_word_length': 3.9616858237547894, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 10, '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': '6949823', 'n_tokens_mistral': 875, 'n_tokens_neox': 803, 'n_words': 210}