20 lines
645 B
Python
20 lines
645 B
Python
import hashlib
|
|
import os
|
|
|
|
|
|
def get_safe_db_name(prefix):
|
|
"""
|
|
PostgreSQL database name limit is 68 characters, which can become
|
|
an issue during testing, because we need to build a unique
|
|
database name using the branch and tox env.
|
|
|
|
Ergo, the following code to ensure the database name is always shorter than 68
|
|
characters.
|
|
"""
|
|
BRANCH_NAME = os.environ.get('BRANCH_NAME', '').replace('/', '-')
|
|
TOX_ENV_NAME = os.environ.get('TOX_ENV_NAME')
|
|
DB_NAME = '_'.join([part for part in [prefix, BRANCH_NAME, TOX_ENV_NAME] if part])
|
|
DB_NAME = hashlib.sha256(DB_NAME.encode()).hexdigest()[:10]
|
|
|
|
return DB_NAME
|