synapse/storage/prepare_database.py
def prepare_database(db_conn, database_engine, config):
    """Prepares a database for usage. Will either create all necessary tables
    or upgrade from an older schema version.

    If `config` is None then prepare_database will assert that no upgrade is
    necessary, *or* will create a fresh database if the database is empty.

    Args:
        db_conn:
        database_engine:
        config (synapse.config.homeserver.HomeServerConfig|None):
            application config, or None if we are connecting to an existing
            database which we expect to be configured already
    """
    try:
        cur = db_conn.cursor()
        version_info = _get_or_create_schema_state(cur, database_engine)

        if version_info:
            user_version, delta_files, upgraded = version_info

            if config is None:
                if user_version != SCHEMA_VERSION:
                    # If we don't pass in a config file then we are expecting to
                    # have already upgraded the DB.
                    raise UpgradeDatabaseException("Database needs to be upgraded")
            else:
                _upgrade_existing_database(
                    cur, user_version, delta_files, upgraded, database_engine, config
                )
        else:
            _setup_new_database(cur, database_engine)

        # check if any of our configured dynamic modules want a database
        if config is not None:
            _apply_module_schemas(cur, database_engine, config)

        cur.close()
        db_conn.commit()
    except Exception:
        db_conn.rollback()
        raise
Prepares a database for usage. Will either create all necessary tables
    or upgrade from an older schema version.

    If `config` is None then prepare_database will assert that no upgrade is
    necessary, *or* will create a fresh database if the database is empty.

    Args:
        db_conn:
        database_engine:
        config (synapse.config.homeserver.HomeServerConfig|None):
            application config, or None if we are connecting to an existing
            database which we expect to be configured already
    
Prepares a database for usage. Will either create all necessary tables
or upgrade from an older schema version.

If `config` is None then prepare_database will assert that no upgrade is
necessary, *or* will create a fresh database if the database is empty.
Prepares a database for usage . Will either create all necessary tables or upgrade from an older schema version . If ` config ` is None then prepare_database will assert that no upgrade is necessary * or * will create a fresh database if the database is empty .
def prepare_database(db_conn, database_engine, config):
    try:
        cur = db_conn.cursor()
        version_info = _get_or_create_schema_state(cur, database_engine)
        if version_info:
            user_version, delta_files, upgraded = version_info
            if config is None:
                if user_version != SCHEMA_VERSION:
                    raise UpgradeDatabaseException("Database needs to be upgraded")
            else:
                _upgrade_existing_database(
                    cur, user_version, delta_files, upgraded, database_engine, config
                )
        else:
            _setup_new_database(cur, database_engine)
        if config is not None:
            _apply_module_schemas(cur, database_engine, config)
        cur.close()
        db_conn.commit()
    except Exception:
        db_conn.rollback()
        raise
def prepare_database ( db_conn , database_engine , config ) : try : cur = db_conn . cursor ( ) version_info = _get_or_create_schema_state ( cur , database_engine ) if version_info : user_version , delta_files , upgraded = version_info if config is None : if user_version != SCHEMA_VERSION : raise UpgradeDatabaseException ( "Database needs to be upgraded" ) else : _upgrade_existing_database ( cur , user_version , delta_files , upgraded , database_engine , config ) else : _setup_new_database ( cur , database_engine ) if config is not None : _apply_module_schemas ( cur , database_engine , config ) cur . close ( ) db_conn . commit ( ) except Exception : db_conn . rollback ( ) raise
Prepares a database for usage.
Prepares a database for usage .
"""Prepares a database for usage. Will either create all necessary tables
    or upgrade from an older schema version.

    If `config` is None then prepare_database will assert that no upgrade is
    necessary, *or* will create a fresh database if the database is empty.

    Args:
        db_conn:
        database_engine:
        config (synapse.config.homeserver.HomeServerConfig|None):
            application config, or None if we are connecting to an existing
            database which we expect to be configured already
    """ # If we don't pass in a config file then we are expecting to # have already upgraded the DB. # check if any of our configured dynamic modules want a database
db_conn
None
database_engine
None
config
application config, or None if we are connecting to an existing
database which we expect to be configured already
application config or None if we are connecting to an existing database which we expect to be configured already