Skip to main content

vespertide_core/schema/
index.rs

1use serde::{Deserialize, Serialize};
2
3use crate::schema::names::{ColumnName, IndexName};
4
5/// A named index on one or more columns of a table.
6///
7/// Index names follow the convention `ix_{table}__{columns}` (double underscore separator).
8/// When `unique` is `true` the index also enforces a uniqueness constraint, equivalent to a
9/// `UNIQUE` constraint but expressed as an index.
10///
11/// `IndexDef` is the normalized form produced from inline `"index"` declarations on columns.
12/// You rarely construct this directly; use the `"index"` field on a [`ColumnDef`] in your model
13/// JSON and let the planner normalize it.
14///
15/// [`ColumnDef`]: crate::schema::ColumnDef
16#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
17#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
18#[serde(rename_all = "snake_case")]
19pub struct IndexDef {
20    /// The index name, conventionally `ix_{table}__{columns}`.
21    pub name: IndexName,
22    /// The ordered list of columns included in the index.
23    pub columns: Vec<ColumnName>,
24    /// When `true`, the index enforces uniqueness across the listed columns.
25    pub unique: bool,
26}