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.apply_additive_migrations(engine)[source]
Bring an existing project database up to the current schema.
A minimal, idempotent stand-in for a migration framework (the project has none), covering the additive changes that are safe to apply automatically on connect:
New tables (e.g.
error) are created viacreate_all, which leaves existing tables and their data untouched. This is how a table added after a project was initialized reaches that project.New nullable columns on existing tables are added with
ALTER TABLE ... ADD COLUMN. Rows that predate a column keep NULL – e.g.pipeline_runrows from beforecode_versionexisted have no recorded code version, which is correct (it is genuinely unknown).
Freshly initialized databases get everything from
create_allalready, so this is effectively a no-op for them. When the pipeline runs, the main process opens the project first, so by the time workers connect every table exists and theircreate_alldoes no DDL.- Parameters:
engine – The SQLAlchemy engine for the project database.
- Returns:
None
- 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)[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.
- 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.