Utilities to manipulate underlying databases - sometimes via an ORM tool.
- class reahl.component.dbutils.SystemControl(config)¶
Used to control all aspects relating to the underlying database as per the configuration of the system.
Any Reahl system is assumed to have a database backing it. Our dealings with a databases vary in two dimentions. The first of these dimantions is the different database backends that can be used. How one controls the backend itself (such as creating users, dropping databases, etc) differs depending on the particular backend used.
Regardless of which backend is used, one can also use an ORM layer on top of the database. Things like instrumenting classes, creating database tables of dealing with database transactions are dependent on the ORM implementation used.
The SystemControl allows you to control all these aspects of the database. It does so by delegating methods relating to the database backend to a
DatabaseControlof the correct kind, and by delegating the methods relating to ORM operations to an
ORMControlof the correct kind.
The type of
DatabaseControlused is inferred from the configured reahlsystem.connection_uri in reahl.config.py. The actual
ORMControlused is configured as the reahlsystem.orm_control in reahl.config.py.
A programmer should use the SystemControl of the system as programmatic interface to the database without regard for which technology-specific classes it delegates to in order to do its work.
Connects and logs into the database.
- property connected¶
Returns True if the system is currently connected to the database.
Disconnects from the database.
Commits the database.
Rolls back the database.
Returns the current size of the database.
Creates the underlying database schema.
Removes the underlying database schema.
Ensures a new clean database exists, with a schema created. This drops an existing database if one is present.
Runs the database migrations relevant to the current system.
Computes the changes in schema between the current database and what the current system expects.
Runs the all the scheduled jobs relevant to the current system.
- create_db_user(super_user_name=None, create_with_password=True)¶
Creates the database user.
Drops the database user.
Drops the database (if it exists).
Creates the database.
- backup_database(directory, super_user_name=None)¶
Backs up the database.
- backup_all_databases(directory, super_user_name=None)¶
Backs up all databases on the current machine.
- restore_database(filename, super_user_name=None)¶
Restores a databases from the given backup.
- restore_all_databases(filename, super_user_name=None)¶
Restores all databases from the given backup.
- class reahl.component.dbutils.DatabaseControl(url, config)¶
An interface to the underlying database backend technology used.
This class has the responsibility to manage the low-level backend operations, such as creating/dropping databases or users.
In order to support a new type of database, subclass this class and implement its methods appropriately for that backend.
- class reahl.component.dbutils.ORMControl¶
An interface to higher-level database operations that may be dependent on the ORM technology used.
This class has the responsibility to manage the higher-level backend operations, such as instrumenting persisted classes, creating database schemas, migration, etc.
In order to support a new type of ORM, subclass this class and implement its methods appropriately for that ORM.
A context manager for code that needs to run in a nested transaction.
Changed in version 5.0: Changed to yield a TransactionVeto which can be used to override when the transaction will be committed or not.
Commits the current transaction. Programmers should not need to deal with such transaction management explicitly, since the framework already manages transactions itself.
Rolls back the current transaction. Programmers should not need to deal with such transaction management explicitly, since the framework already manages transactions itself.