Module for implementations of database backends.
aiida.backends.
get_backend_manager
Get an instance of the BackendManager for the current backend.
backend – the type of the database backend
BackendManager
Module for settings and utilities to determine and set the database schema versions.
aiida.backends.manager.
Bases: object
object
Class to manage the database schema and environment.
__dict__
__module__
__weakref__
list of weak references to the object (if defined)
_load_backend_environment
Load the backend environment.
kwargs – keyword arguments that will be passed on to the backend specific scoped session getter function.
_migrate_database_generation
Migrate the database schema generation.
Warning
this should NEVER be called directly because there is no validation performed on whether the current database schema generation and version can actually be migrated.
This normally just consists out of setting the schema generation value, but depending on the backend more might be needed. In that case, this method should be overridden and call super first, followed by the additional logic that is required.
_migrate_database_version
Migrate the database to the current schema version.
_settings_manager
get_schema_generation_database
Return the database schema generation.
distutils.version.LooseVersion with schema generation of the database
get_schema_version_code
Return the code schema version.
get_schema_version_database
Return the database schema version.
distutils.version.LooseVersion with schema version of the database
get_schema_version_reset
Return schema version the database should have to be able to automatically reset to code schema generation.
schema_generation_code – the schema generation of the code.
schema version
get_settings_manager
Return an instance of the SettingsManager.
SettingsManager
is_database_schema_ahead
Determine whether the database schema version is ahead of the code schema version.
this will not check whether the schema generations are equal
boolean, True if the database schema version is ahead of the code schema version.
load_backend_environment
profile – the profile whose backend environment to load
validate_schema – boolean, if True, validate the schema first before loading the environment.
migrate
Migrate the database to the latest schema generation or version.
reset_backend_environment
Reset the backend environment.
set_schema_generation_database
Set the database schema generation.
generation – string with schema generation to set
set_schema_version_database
Set the database schema version.
version – string with schema version to set
validate_schema
Validate that the current database generation and schema are up-to-date with that of the code.
profile – the profile for which to validate the database schema
aiida.common.exceptions.ConfigurationError – if database schema version or generation is not up-to-date
validate_schema_generation
Validate that the current database schema generation is up-to-date with that of the code.
aiida.common.exceptions.IncompatibleDatabaseSchema – if database schema generation is not up-to-date
validate_schema_generation_for_migration
Validate whether the current database schema generation can be migrated.
aiida.common.exceptions.IncompatibleDatabaseSchema – if database schema generation cannot be migrated
validate_schema_version
Validate that the current database schema version is up-to-date with that of the code.
aiida.common.exceptions.IncompatibleDatabaseSchema – if database schema version is not up-to-date
validate_schema_version_for_migration
Validate whether the current database schema version can be migrated.
this will not validate that the schema generation is correct.
aiida.common.exceptions.IncompatibleDatabaseSchema – if database schema version cannot be migrated
Setting
Bases: tuple
tuple
__getnewargs__
Return self as a plain tuple. Used by copy and pickle.
__new__
Create new instance of Setting(key, value, description, time)
__repr__
Return a nicely formatted representation string
__slots__
_asdict
Return a new dict which maps field names to their values.
_field_defaults
_fields
_fields_defaults
_make
Make a new Setting object from a sequence or iterable
_replace
Return a new Setting object replacing specified fields with new values
description
Alias for field number 2
key
Alias for field number 0
time
Alias for field number 3
value
Alias for field number 1
Class to get, set and delete settings from the DbSettings table.
delete
Delete the setting with the given key.
key – the key identifying the setting
~aiida.common.exceptions.NotExistent if the settings does not exist
get
Return the setting with the given key.
set
Return the settings with the given key.
value – the value for the setting
description – optional setting description
Basic test classes.
aiida.backends.testbase.
AiidaPostgresTestCase
Bases: aiida.backends.testbase.AiidaTestCase
aiida.backends.testbase.AiidaTestCase
Setup postgres tests.
setUpClass
Setup the PGTest postgres test cluster.
tearDownClass
Close the PGTest postgres test cluster.
AiidaTestCase
Bases: unittest.case.TestCase
unittest.case.TestCase
This is the base class for AiiDA tests, independent of the backend.
Internally it loads the AiidaTestImplementation subclass according to the current backend.
__backend_instance
_class_was_setup
_computer
_user
assertClickResultNoException
assertClickSuccess
backend
clean_db
Clean up database and reset caches.
Resets AiiDA manager cache, which could otherwise be left in an inconsistent state when cleaning the database.
clean_repository
Cleans up file repository.
computer
A class that, when used as a decorator, works as if the two decorators @property and @classmethod where applied together (i.e., the object works as a property, both for the Class and for any of its instance; and is called with the class cls rather than with the instance as its first argument).
get_backend_class
Get backend class.
insert_data
This method setups the database (by creating a default user) and inserts default data into the database (which is for the moment a default computer).
refurbish_db
Clean up database and repopulate with initial data.
Combines clean_db and insert_data.
Set up test class.
tearDown
Hook method for deconstructing the test fixture after testing it.
Tear down test class.
Note: Also cleans file repository.
user
user_email
check_if_tests_can_run
Verify that the currently loaded profile is a test profile, otherwise raise TestsNotAllowedError.
get_default_user
Creates and stores the default user in the database.
Default user email is taken from current profile. No-op if user already exists. The same is done in verdi setup.
kwargs – Additional information to use for new user, i.e. ‘first_name’, ‘last_name’ or ‘institution’.
the User
User
Implementation-dependednt base tests
aiida.backends.testimplbase.
AiidaTestImplementation
Bases: abc.ABC
abc.ABC
Backend-specific test implementations.
__abstractmethods__
_abc_impl
_backend
Get the backend.
This method fully cleans the DB.
Backend-agnostic utility functions
aiida.backends.utils.
create_scoped_session_factory
Create scoped SQLAlchemy session factory
create_sqlalchemy_engine
Create SQLAlchemy engine (to be used for QueryBuilder queries)
kwargs – keyword arguments that will be passed on to sqlalchemy.create_engine. See https://docs.sqlalchemy.org/en/13/core/engines.html?highlight=create_engine#sqlalchemy.create_engine for more info.
delete_nodes_and_connections
Backend-agnostic function to delete Nodes and connections