autowisp.database.interface module
Class Inheritance Diagram

Connect to the database and provide a session scope for queries.
- autowisp.database.interface.DB_URL_FNAME = 'autowisp_db.url'
Filename (relative to project home) where a non-SQLite connection URL is stored.
When a project is initialised with a centralised database (MySQL, MariaDB, etc.) the connection URL is written to this file so that subsequent calls to
set_project_home()with only the directory path can reconnect without requiring the caller to supply the URL again.
- autowisp.database.interface.get_project_home()[source]
Return the project home directory currently being used.
- autowisp.database.interface.initialize_cmdline_database()[source]
Initialize the current database HDF5 structure tables.
- autowisp.database.interface.set_project_home(project_home, db_url=None, new_project=False, *, migrate=False, assume_backed_up=False)[source]
Set the database engine and session for the given project home.
On first use with a non-SQLite
db_urlthe URL is persisted to<project_home>/autowisp_db.urlso that subsequent calls with onlyproject_homereconnect to the same database automatically.- Parameters:
project_home – Directory used as the project home. For SQLite (the default), the database file
autowisp.dbis created here. For centralised databases the directory is still used for other project files (HDF5 products, etc.). PassNoneto use the platform-appropriate user data directory.db_url – SQLAlchemy connection URL. When omitted (or
None) the function first checks for a previously saved URL in<project_home>/autowisp_db.url; if none is found it falls back to an SQLite database inproject_home:sqlite:///<project_home>/autowisp.db?timeout=100&uri=true. To connect to a centralised server pass the full URL, e.g.:"mysql+pymysql://user:password@host:3306/dbname""mariadb+pymysql://user:password@host:3306/dbname"Passing an explicit URL raises an error if a saved URL is found.new_project – Pass
Truewhen this call is creating a project rather than opening an existing one. The target database must then contain none of the AutoWISP tables, since project creation goes on to drop and recreate them (seeinitialize_database) – which on a centralised server would silently destroy whichever project already lives in that database. Independent of backend: it equally catches an SQLite project home that already holds a database.migrate – Bring the schema up to date rather than merely requiring that it already is. Off by default because every process opening a project calls this, including every pipeline worker, and concurrent schema changes from dozens of workers is exactly what must not happen. Set it only where a single process is known to be in charge: the
wisp-migratecommand, the browser interface selecting a project, and the main process of a pipeline run.assume_backed_up – Passed through to
migrate_project(); only meaningful withmigrate. Required to migrate a server database, which cannot be copied aside automatically.
- Returns:
- The result of
migrate_project()when migrateis set and the project already existed, otherwise None.
- The result of
- Return type:
dict or None
- Raises:
DatabaseError – If
new_projectis set and the target database already contains AutoWISP tables. Nothing is written or dropped in that case: the URL file is persisted only after this check passes.
- autowisp.database.interface.snapshot_row(orm_obj, *, exclude=())[source]
Freeze all mapped columns of a live ORM instance into a FrozenRow.
Must be called while
orm_objis still attached/loaded (i.e. inside thestart_db_session()block that produced it), otherwise touching an expired column would raiseDetachedInstanceError.