def choose_database_name(metadata, config):
    """
    Choose the database name to use.

    As a default, databases should be named after the service that uses them. In addition,
    database names should be different between unit testing and runtime so that there is
    no chance of a unit test dropping a real database by accident.

    """
    if config.database_name is not None:
        # we allow -- but do not encourage -- database name configuration
        return config.database_name

    if metadata.testing:
        # by convention, we provision different databases for unit testing and runtime
        return f"{metadata.name}_test_db"

    return f"{metadata.name}_db"