<commit_before>from alembic import util
from alembic.context import get_context
from sqlalchemy.types import NULLTYPE
from sqlalchemy import schema

__all__ = [
            'alter_column', 
            'create_foreign_key', 
            'create_unique_constraint', 
            'execute']

def alter_column(table_name, column_name, 
                    nullable=util.NO_VALUE,
                    server_default=util.NO_VALUE,
                    name=util.NO_VALUE,
                    type_=util.NO_VALUE
):
    """Issue ALTER COLUMN using the current change context."""

    context.alter_column(table_name, column_name, 
        nullable=nullable,
        server_default=server_default,
        name=name,
        type_=type_
    )


def _foreign_key_constraint(name, source, referent, local_cols, remote_cols):
    m = schema.MetaData()
    t1 = schema.Table(source, m, 
            *[schema.Column(n, NULLTYPE) for n in local_cols])
    t2 = schema.Table(referent, m, 
            *[schema.Column(n, NULLTYPE) for n in remote_cols])

    f = schema.ForeignKeyConstraint(local_cols, 
                                        ["%s.%s" % (referent, name) 
                                        for name in remote_cols],
                                        name=name
                                        )
    t1.append_constraint(f)

    return f

def _unique_constraint(name, source, local_cols):
    t = schema.Table(source, schema.MetaData(), 
                *[schema.Column(n, NULLTYPE) for n in local_cols])
    return schema.UniqueConstraint(*t.c, name=name)

def _table(name, *columns, **kw):
    m = schema.MetaData()
    t = schema.Table(name, m, *columns, **kw)
    for f in t._foreign_keys:
        _ensure_table_for_fk(m, f)
    return t

def _ensure_table_for_fk(metadata, fk):
    """create a placeholder Table object for the referent of a
    ForeignKey.

    """
    if isinstance(fk._colspec, basestring):
        table_key, cname = fk._colspec.split('.')
        if '.' in table_key:
            tokens = tname.split('.')
            sname = ".".join(tokens[0:-1])
            tname = tokens[-1]
        else:
            tname = table_key
            sname = None
        if table_key not in metadata.tables:<commit_msg>use public foreign keys collection<commit_after>from alembic import util
from alembic.context import get_context
from sqlalchemy.types import NULLTYPE
from sqlalchemy import schema

__all__ = [
            'alter_column', 
            'create_foreign_key', 
            'create_unique_constraint', 
            'execute']

def alter_column(table_name, column_name, 
                    nullable=util.NO_VALUE,
                    server_default=util.NO_VALUE,
                    name=util.NO_VALUE,
                    type_=util.NO_VALUE
):
    """Issue ALTER COLUMN using the current change context."""

    context.alter_column(table_name, column_name, 
        nullable=nullable,
        server_default=server_default,
        name=name,
        type_=type_
    )


def _foreign_key_constraint(name, source, referent, local_cols, remote_cols):
    m = schema.MetaData()
    t1 = schema.Table(source, m, 
            *[schema.Column(n, NULLTYPE) for n in local_cols])
    t2 = schema.Table(referent, m, 
            *[schema.Column(n, NULLTYPE) for n in remote_cols])

    f = schema.ForeignKeyConstraint(local_cols, 
                                        ["%s.%s" % (referent, name) 
                                        for name in remote_cols],
                                        name=name
                                        )
    t1.append_constraint(f)

    return f

def _unique_constraint(name, source, local_cols):
    t = schema.Table(source, schema.MetaData(), 
                *[schema.Column(n, NULLTYPE) for n in local_cols])
    return schema.UniqueConstraint(*t.c, name=name)

def _table(name, *columns, **kw):
    m = schema.MetaData()
    t = schema.Table(name, m, *columns, **kw)
    for f in t.foreign_keys:
        _ensure_table_for_fk(m, f)
    return t

def _ensure_table_for_fk(metadata, fk):
    """create a placeholder Table object for the referent of a
    ForeignKey.

    """
    if isinstance(fk._colspec, basestring):
        table_key, cname = fk._colspec.split('.')
        if '.' in table_key:
            tokens = tname.split('.')
            sname = ".".join(tokens[0:-1])
            tname = tokens[-1]
        else:
            tname = table_key
            sname = None
        if table_key not in metadata.tables:
{'fraction_non_alphanumeric': 0.09862892525431226, 'fraction_numerical': 0.0026536930561698365, 'mean_word_length': 1.9313026571613738, '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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5848457', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1304, 'n_words': 313}