resonance.api.data.schema¶
resonance.api.data.schema
¶
create_beamtime_schema(conn)
¶
Create all per-beamtime tables, indexes, and pragmas.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Open connection to the beamtime SQLite database file. |
required |
Raises:
| Type | Description |
|---|---|
DatabaseError
|
If DDL execution fails due to a malformed database or I/O error. |
Notes
Each beamtime session is stored in its own SQLite .db file alongside
a Zarr store directory. The image_refs table holds references into
the Zarr array (group path and frame index) rather than binary BLOBs,
keeping the SQLite file small and enabling memory-mapped array access.
Foreign keys are enforced on every connection via PRAGMA foreign_keys = ON,
which must be re-applied per connection because SQLite resets it on open.
Source code in src/resonance/api/data/schema.py
migrate_beamtime_schema(conn, target_version=BEAMTIME_SCHEMA_VERSION)
¶
Apply pending schema migrations up to target_version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Open connection to the beamtime SQLite database file. |
required |
target_version
|
int
|
Schema version to migrate to. Defaults to BEAMTIME_SCHEMA_VERSION. |
BEAMTIME_SCHEMA_VERSION
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If target_version is less than the current schema version (downgrade not supported). |
Source code in src/resonance/api/data/schema.py
create_index_schema(conn)
¶
Create master index tables, indexes, and pragmas.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Open connection to the master index SQLite database file. |
required |
Raises:
| Type | Description |
|---|---|
DatabaseError
|
If DDL execution fails due to a malformed database or I/O error. |
Notes
The master index database aggregates metadata from all per-beamtime
databases into three tables: researchers, beamtimes, and
runs_index. This allows cross-beamtime queries without opening
individual session databases. The runs_index table mirrors key
fields from the per-beamtime runs table, identified by the same
uid. Foreign keys are enforced via PRAGMA foreign_keys = ON,
which must be re-applied per connection.
Source code in src/resonance/api/data/schema.py
migrate_index_schema(conn, target_version=INDEX_SCHEMA_VERSION)
¶
Apply pending index schema migrations up to target_version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Open connection to the master index SQLite database file. |
required |
target_version
|
int
|
Schema version to migrate to. Defaults to |
INDEX_SCHEMA_VERSION
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the database's current |
NotImplementedError
|
If migrations are required (current_version < target_version) but no migration path has been implemented yet. |
Notes
Migration steps are applied sequentially from current_version + 1 up to
target_version. Version 1 is the initial schema; future versions will add
individual ALTER TABLE or data-transform statements here.