<commit_before>from __future__ import with_statement

import logging
import sys
from logging.config import fileConfig
from alembic import context

import sideboard
import uber
from sideboard.lib.sa import CoerceUTF8, UTCDateTime, UUID
from uber.migration import version_locations_option
from uber.models import Choice, MultiChoice, Session


# This is the alembic Config object, which provides access to "alembic.ini".
alembic_config = context.config

version_locations = alembic_config.get_main_option('version_locations')
assert version_locations == version_locations_option, (
        'alembic must be run using the sep command:\n'
        'sep alembic {}'.format(' '.join(sys.argv[1:])))

# Interpret the config file for Python logging. This sets up alembic loggers.
if alembic_config.config_file_name:
    fileConfig(alembic_config.config_file_name)
logger = logging.getLogger('alembic.env')

# Add the model's MetaData object here for "autogenerate" support.
target_metadata = Session.BaseClass.metadata


def include_object(object, name, type_, reflected, compare_to):
    """Exclude alembic's own version tables from alembic's consideration."""
    return not name.startswith('alembic_version')


def render_item(type_, obj, autogen_context):
    """Apply custom rendering for selected items."""
    if type_ == 'type':
        if isinstance(obj, Choice):
            return 'sa.Integer()'
        elif isinstance(obj, UTCDateTime):
            autogen_context.imports.add('import sideboard.lib.sa')
            return 'sideboard.lib.sa.UTCDateTime()'
        elif isinstance(obj, (CoerceUTF8, MultiChoice)):
            return 'sa.Unicode()'
        elif isinstance(obj, UUID):
            autogen_context.imports.add('import sideboard.lib.sa')
            return 'sideboard.lib.sa.UUID()'

    # Default rendering for other objects
    return False


def process_revision_directives(context, revision, directives):
    """If an empty migration is autogenerated, don't create a script."""
    if alembic_config.cmd_opts.autogenerate:
        script = directives[0]
        if script.upgrade_ops.is_empty():
            directives[:] = []
            logger.info('Nothing to do.')


def run_migrations_offline():
    """Run migrations in "offline" mode.

    This configures the context with just a URL and not an Engine, though an
    Engine is acceptable here as well.  By skipping the Engine creation we
    don't even need a DBAPI to be available.
<commit_msg>Revert "Use Sideboard for Alembic migrations"<commit_after>from __future__ import with_statement

import logging
import sys
from logging.config import fileConfig
from alembic import context

import sideboard
import uber
from residue import CoerceUTF8, UTCDateTime, UUID
from uber.migration import version_locations_option
from uber.models import Choice, MultiChoice, Session


# This is the alembic Config object, which provides access to "alembic.ini".
alembic_config = context.config

version_locations = alembic_config.get_main_option('version_locations')
assert version_locations == version_locations_option, (
        'alembic must be run using the sep command:\n'
        'sep alembic {}'.format(' '.join(sys.argv[1:])))

# Interpret the config file for Python logging. This sets up alembic loggers.
if alembic_config.config_file_name:
    fileConfig(alembic_config.config_file_name)
logger = logging.getLogger('alembic.env')

# Add the model's MetaData object here for "autogenerate" support.
target_metadata = Session.BaseClass.metadata


def include_object(object, name, type_, reflected, compare_to):
    """Exclude alembic's own version tables from alembic's consideration."""
    return not name.startswith('alembic_version')


def render_item(type_, obj, autogen_context):
    """Apply custom rendering for selected items."""
    if type_ == 'type':
        if isinstance(obj, Choice):
            return 'sa.Integer()'
        elif isinstance(obj, UTCDateTime):
            autogen_context.imports.add('import residue')
            return 'residue.UTCDateTime()'
        elif isinstance(obj, (CoerceUTF8, MultiChoice)):
            return 'sa.Unicode()'
        elif isinstance(obj, UUID):
            autogen_context.imports.add('import residue')
            return 'residue.UUID()'

    # Default rendering for other objects
    return False


def process_revision_directives(context, revision, directives):
    """If an empty migration is autogenerated, don't create a script."""
    if alembic_config.cmd_opts.autogenerate:
        script = directives[0]
        if script.upgrade_ops.is_empty():
            directives[:] = []
            logger.info('Nothing to do.')


def run_migrations_offline():
    """Run migrations in "offline" mode.

    This configures the context with just a URL and not an Engine, though an
    Engine is acceptable here as well.  By skipping the Engine creation we
    don't even need a DBAPI to be available.

{'fraction_non_alphanumeric': 0.08842019874264855, 'fraction_numerical': 0.0016223889677550193, 'mean_word_length': 3.7976653696498053, 'pattern_counts': {'":': 0, '<': 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': '6090092', 'n_tokens_mistral': 1427, 'n_tokens_neox': 1386, 'n_words': 447}