# Path: gdcdatamodel/models/utils.py
# def py3_to_bytes(bytes_or_str):
#     if sys.version_info[0] > 2 and isinstance(bytes_or_str, str):
#         return bytes_or_str.encode('utf-8')
#     return bytes_or_str


import logging
import hashlib
from sqlalchemy import Index, func
from gdcdatamodel.models.utils import py3_to_bytes
"""





logger = logging.getLogger(__name__)


def index_name(cls, description):
    """Standardize index naming.  Because of PostgreSQL's name character
    limit, this follows a similar scheme to shortening edge names in
    `gdcdatamodel.generate_edge_tablename()`

    For long names, take the first 8 characters of a hash of the full,
    un-truncated table name *before* we truncate and prepend this to
    the truncation.  This gets us a name like
    ``index_4df72441_famihist_lower_submitte_id``.  This is yet
    another rather an undesirable workaround. - jsm

    """

    name = 'index_{}_{}'.format(cls.__tablename__, description)

    # If the name is too long, prepend it with the first 8 hex of it's hash
    # truncate the each part of the name
    if len(name) > 40:
        oldname = index_name
        logger.debug('Edge tablename {} too long, shortening'.format(oldname))
        name = 'index_{}_{}_{}'.format(

# Path: gdcdatamodel/models/utils.py
# def py3_to_bytes(bytes_or_str):
#     if sys.version_info[0] > 2 and isinstance(bytes_or_str, str):
#         return bytes_or_str.encode('utf-8')
#     return bytes_or_str


# Path: gdcdatamodel/models/indexes.py
import logging
import hashlib
from sqlalchemy import Index, func
from gdcdatamodel.models.utils import py3_to_bytes

"""





logger = logging.getLogger(__name__)


def index_name(cls, description):
    """Standardize index naming.  Because of PostgreSQL's name character
    limit, this follows a similar scheme to shortening edge names in
    `gdcdatamodel.generate_edge_tablename()`

    For long names, take the first 8 characters of a hash of the full,
    un-truncated table name *before* we truncate and prepend this to
    the truncation.  This gets us a name like
    ``index_4df72441_famihist_lower_submitte_id``.  This is yet
    another rather an undesirable workaround. - jsm

    """

    name = 'index_{}_{}'.format(cls.__tablename__, description)

    # If the name is too long, prepend it with the first 8 hex of it's hash
    # truncate the each part of the name
    if len(name) > 40:
        oldname = index_name
        logger.debug('Edge tablename {} too long, shortening'.format(oldname))
        name = 'index_{}_{}_{}'.format(

            hashlib.md5(py3_to_bytes(cls.__tablename__)).hexdigest()[:8],