This directory contains the database schema files for the MOLLER experiment analysis database.
The database schema is maintained in the separate MOLLER-parity-schema repository as a DBML (Database Markup Language) file. This mollerdb repository references it as a git submodule and generates the necessary artifacts for C++ integration.
qwparity_schema.sql: PostgreSQL SQL schema generated from the DBML source during build (not in repository)custom_types.csv: Custom type mapping for sqlpp23 to handle PostgreSQL ENUMs../include/mollerdb/schema/qwparity_schema.h: C++ header file generated by sqlpp23 during build (not in repository)
The schema files are automatically generated during the CMake build process:
- SQL Generation: The DBML file from the submodule is converted to PostgreSQL SQL using
dbml2sql - C++ Header Generation: The SQL file is processed by
sqlpp23-ddl2cppto generate type-safe C++ headers
These files are generated in the source tree and are excluded from version control via .gitignore.
The schema comes from the MOLLER-parity-schema repository which is included as a git submodule at thirdparty/MOLLER-parity-schema. To update the schema:
cd thirdparty/MOLLER-parity-schema
git pull origin main
cd ../..
git add thirdparty/MOLLER-parity-schema
git commit -m "Update database schema submodule"The schema files will be automatically regenerated during the next build:
pip install . --verboseThe build process requires:
- Node.js and npm: For the
@dbml/clipackage (providesdbml2sql) - Python 3: For the
sqlpp23-ddl2cppscript
Install the required tools:
npm install -g @dbml/cliThe MOLLER-parity-schema repository has a CI workflow that automatically:
- Converts
qwparity_schema.dbmlto SQL (both MySQL and PostgreSQL) - Generates SVG diagrams of the schema
- Publishes documentation to GitHub Pages
This mollerdb repository consumes the PostgreSQL version of the schema.
PostgreSQL ENUM types are mapped to sqlpp::text in C++ for simplicity. The mappings are defined in custom_types.csv.
The MOLLER database schema uses PostgreSQL ENUM types for various fields (e.g., runlet_full_run_enum, analysis_beam_mode_enum). Since sqlpp23 does not natively support PostgreSQL ENUM types, the custom_types.csv file provides a mapping that tells the sqlpp23-ddl2cpp code generator how to represent these types in C++.
Without this mapping, the schema generation would fail when encountering ENUM types. The file is passed to sqlpp23-ddl2cpp via the --path-to-custom-types flag during the build process.
The file follows the sqlpp23-ddl2cpp custom types format:
- Each line:
base_type,custom_type1,custom_type2,... - Base type is a sqlpp23 data type (text, integral, floating_point, etc.)
- Custom types are comma-separated PostgreSQL types to map to that base type
Example:
text,runlet_full_run_enum,analysis_beam_mode_enum
This maps PostgreSQL ENUMs to C++ std::optional<::sqlpp::text> for maximum compatibility.
During the CMake build process:
- The DBML schema is converted to PostgreSQL SQL (which includes ENUM type definitions)
- The
sqlpp23-ddl2cppscript reads the SQL and thecustom_types.csvfile - For each PostgreSQL ENUM type listed in the CSV, the generator creates a C++
textfield instead of failing - The generated C++ header allows you to read/write ENUM values as strings
This approach provides maximum flexibility and compatibility while maintaining type information in the database.
The generated C++ header (qwparity_schema.h) provides type-safe table and column representations for use with sqlpp23, a C++ SQL library. This allows for compile-time SQL query validation and type safety.