Skip to main content

quorum_public/db/
schema.rs

1//! Database schema management.
2//! This module provides functions to initialize and manage the database schema.
3
4use std::error::Error;
5
6/// Initializes the database schema by executing the initial schema script.
7/// This function reads the schema from a file and executes it against the provided database connection.
8///
9/// # Arguments
10/// * `db` - A reference to the database connection.
11///
12/// # Returns
13/// * `Ok(())` if the schema was initialized successfully.
14/// * `Err(Box<dyn Error>)` if there was an error during initialization.
15///
16/// # Example
17/// ```
18/// use crate::db::schema;
19/// async fn setup_database(db: &crate::db::DB) -> Result<(), Box<dyn Error>> {
20///     schema::init(db).await?;
21///     Ok(())
22/// }
23///```
24pub async fn init(db: &quorum_core::db::DB) -> Result<(), Box<dyn Error>> {
25    let schema = include_str!("../../initial.surql");
26
27    db.query(schema).await?.check()?;
28
29    Ok(())
30}