Exemplo n.º 1
0
def check_schema_version():
    """
    Check if the version stored in the database is the same of the version
    of the code.

    :note: if the DbSetting table does not exist, this function does not
      fail. The reason is to avoid to have problems before running the first
      migrate call.

    :note: if no version is found, the version is set to the version of the
      code. This is useful to have the code automatically set the DB version
      at the first code execution.

    :raise ConfigurationError: if the two schema versions do not match.
      Otherwise, just return.
    """
    import aiida.backends.djsite.db.models
    from aiida.backends.utils import (get_current_profile,
                                      set_db_schema_version,
                                      get_db_schema_version)
    from django.db import connection
    from aiida.common.exceptions import ConfigurationError

    # Do not do anything if the table does not exist yet
    if 'db_dbsetting' not in connection.introspection.table_names():
        return

    code_schema_version = aiida.backends.djsite.db.models.SCHEMA_VERSION
    db_schema_version = get_db_schema_version()

    if db_schema_version is None:
        # No code schema defined yet, I set it to the code version
        set_db_schema_version(code_schema_version)
        db_schema_version = get_db_schema_version()

    if code_schema_version != db_schema_version:
        raise ConfigurationError(
            "The code schema version is {}, but the version stored in the "
            "database (DbSetting table) is {}, stopping.\n"
            "To migrate to latest version, go to aiida.backends.djsite and "
            "run:\nverdi daemon stop\n python manage.py --aiida-profile={} migrate"
            .format(code_schema_version, db_schema_version,
                    get_current_profile()))
Exemplo n.º 2
0
def check_schema_version():
    """
    Check if the version stored in the database is the same of the version
    of the code.

    :note: if the DbSetting table does not exist, this function does not
      fail. The reason is to avoid to have problems before running the first
      migrate call.

    :note: if no version is found, the version is set to the version of the
      code. This is useful to have the code automatically set the DB version
      at the first code execution.

    :raise ConfigurationError: if the two schema versions do not match.
      Otherwise, just return.
    """
    from aiida.common.exceptions import ConfigurationError
    from aiida.backends import sqlalchemy as sa
    from sqlalchemy.engine import reflection
    from aiida.backends.sqlalchemy.models import SCHEMA_VERSION
    from aiida.backends.utils import (get_db_schema_version,
                                      set_db_schema_version,
                                      get_current_profile)

    # Do not do anything if the table does not exist yet
    inspector = reflection.Inspector.from_engine(sa.session.bind)
    if 'db_dbsetting' not in inspector.get_table_names():
        return

    code_schema_version = SCHEMA_VERSION
    db_schema_version = get_db_schema_version()

    if db_schema_version is None:
        # No code schema defined yet, I set it to the code version
        set_db_schema_version(code_schema_version)
        db_schema_version = get_db_schema_version()

    if code_schema_version != db_schema_version:
        raise ConfigurationError(
            "The code schema version is {}, but the version stored in the"
            "database (DbSetting table) is {}, stopping.\n".format(
                code_schema_version, db_schema_version))
Exemplo n.º 3
0
def _update_schema_version(version, apps, schema_editor):
    from aiida.backends.utils import set_db_schema_version
    set_db_schema_version(version)