Skip to main content

ordinary_config/app/database/
mod.rs

1// Copyright (C) 2026 The Ordinary Authors.
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5use ordinary_types::Field;
6use serde::{Deserialize, Serialize};
7
8#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
9#[cfg_attr(feature = "docs", derive(schemars::JsonSchema))]
10#[derive(Deserialize, Serialize, Debug, Clone, Default)]
11pub struct DatabaseConfig {
12    /// model definitions for the app database
13    pub models: Vec<DatabaseModelConfig>,
14    /// path to JSON formatted seeds file
15    pub seeds_path: Option<String>,
16}
17
18/// Defines a model in the Ordinary Database.
19#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
20#[cfg_attr(feature = "docs", derive(schemars::JsonSchema))]
21#[derive(Deserialize, Serialize, Debug, Clone)]
22pub struct DatabaseModelConfig {
23    /// Index of the model. Used for its kind
24    /// for storage keys. There can be no gaps in
25    /// index values.
26    ///
27    /// Note: the first (0) index is always skipped as it
28    /// is reserved for the item UUID.
29    pub idx: u8,
30    /// Name of the model.
31    pub name: String,
32    /// Fields on the model.
33    pub fields: Vec<Field>,
34    /// Every model is generated with a UUID key. If this value
35    /// is blank, it will default to V4. If you'd like records to
36    /// be ordered by time, V7 is recommended.
37    #[serde(skip_serializing_if = "Option::is_none")]
38    #[serde(default)]
39    pub uuid: Option<UuidVersion>,
40}
41
42#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
43#[cfg_attr(feature = "docs", derive(schemars::JsonSchema))]
44#[derive(Deserialize, Serialize, Debug, Clone, Default)]
45pub enum UuidVersion {
46    V4,
47    #[default]
48    V7,
49}