#[non_exhaustive]pub enum TableConstraint {
PrimaryKey {
auto_increment: bool,
columns: Vec<ColumnName>,
strategy: PrimaryKeyAdditionStrategy,
},
Unique {
name: Option<String>,
columns: Vec<ColumnName>,
strategy: UniqueConstraintStrategy,
},
ForeignKey {
name: Option<String>,
columns: Vec<ColumnName>,
ref_table: TableName,
ref_columns: Vec<ColumnName>,
on_delete: Option<ReferenceAction>,
on_update: Option<ReferenceAction>,
orphan_strategy: ForeignKeyOrphanStrategy,
},
Check {
name: String,
expr: String,
strategy: CheckViolationStrategy,
},
Index {
name: Option<String>,
columns: Vec<ColumnName>,
},
}Expand description
A table-level constraint produced by TableDef::normalize.
Inline column constraints (primary_key, unique, index, foreign_key) declared in model
JSON files are converted into TableConstraint variants during normalization. You rarely
construct these directly; the planner and SQL generator consume them.
This enum is #[non_exhaustive]: new variants may be added in future releases.
Downstream match expressions should include a wildcard arm.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
PrimaryKey
Primary key constraint, optionally with auto-increment (serial / identity) semantics.
strategy controls how pre-existing duplicate rows in the
chosen column set are handled when this constraint is added to
an already-populated table. The canonical default is
[PrimaryKeyAdditionStrategy::DeleteDuplicates { keep: KeepPolicy::First }]
(omitted from the JSON wire format). NULL violations on PK
columns are handled separately by the F1 fill_with mechanism;
the revision CLI prompts for fill values on every nullable PK
column.
strategy is stripped from model.schema.json but
preserved in migration.schema.json.
Unique
Unique constraint ensuring no two rows share the same value(s) in the listed columns.
strategy controls how pre-existing duplicate rows are handled when
this constraint is added to an already-populated table. The
canonical default is [UniqueConstraintStrategy::DeleteDuplicates { keep: KeepPolicy::First }],
which matches v0.1.x behaviour and is omitted from the JSON wire
format. Other strategies (e.g. DeleteDuplicates) emit a pre-cleanup
step ahead of ADD CONSTRAINT so the migration succeeds even when
production data has duplicates.
strategy is stripped from model.schema.json by the
schema generator (vespertide-schema-gen), but preserved in
migration.schema.json since migration files carry the
revision CLI’s stamped choice.
ForeignKey
Foreign key constraint linking columns in this table to columns in another table.
orphan_strategy controls how pre-existing orphan rows are
handled when this constraint is added to an already-populated
table. The canonical default is
ForeignKeyOrphanStrategy::NullifyOrphans (omitted from the
JSON wire format). The revision CLI re-prompts the user for an
explicit choice; the default exists only so v0.1.x model files
continue to deserialize.
orphan_strategy is stripped from model.schema.json by
the schema generator but preserved in migration.schema.json.
Fields
columns: Vec<ColumnName>ref_columns: Vec<ColumnName>on_delete: Option<ReferenceAction>on_update: Option<ReferenceAction>orphan_strategy: ForeignKeyOrphanStrategyCheck
Arbitrary SQL CHECK expression enforced by the database on every write.
strategy controls how pre-existing violating rows are handled when
this constraint is added to an already-populated table. The
canonical default is CheckViolationStrategy::NullifyViolatingColumn
(omitted from the JSON wire format). The revision CLI re-prompts
the user for an explicit choice; the default exists only so v0.1.x
model files continue to deserialize.
Cleanup SQL is emitted only when the expression matches a narrow
recognisable shape (<col> <op> <literal> or <col> IN (...));
more complex expressions skip pre-cleanup and rely on the database
to validate at apply time.
strategy is stripped from model.schema.json but
preserved in migration.schema.json.
Index
Non-unique index to speed up queries on the listed columns.
Implementations§
Source§impl TableConstraint
impl TableConstraint
Sourcepub fn kind(&self) -> ConstraintKind
pub fn kind(&self) -> ConstraintKind
Returns the high-level kind of this constraint.
Sourcepub fn columns(&self) -> &[ColumnName]
pub fn columns(&self) -> &[ColumnName]
Returns the columns referenced by this constraint. For Check constraints, returns an empty slice (expression-based, not column-based).
Sourcepub fn with_prefix(self, prefix: &str) -> Self
pub fn with_prefix(self, prefix: &str) -> Self
Apply a prefix to referenced table names in this constraint.
Only affects ForeignKey constraints (which reference other tables).
Trait Implementations§
Source§impl Clone for TableConstraint
impl Clone for TableConstraint
Source§fn clone(&self) -> TableConstraint
fn clone(&self) -> TableConstraint
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TableConstraint
impl Debug for TableConstraint
Source§impl<'de> Deserialize<'de> for TableConstraint
impl<'de> Deserialize<'de> for TableConstraint
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for TableConstraint
Source§impl JsonSchema for TableConstraint
impl JsonSchema for TableConstraint
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl Ord for TableConstraint
impl Ord for TableConstraint
Source§fn cmp(&self, other: &TableConstraint) -> Ordering
fn cmp(&self, other: &TableConstraint) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for TableConstraint
impl PartialEq for TableConstraint
Source§fn eq(&self, other: &TableConstraint) -> bool
fn eq(&self, other: &TableConstraint) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialOrd for TableConstraint
impl PartialOrd for TableConstraint
Source§impl Serialize for TableConstraint
impl Serialize for TableConstraint
impl StructuralPartialEq for TableConstraint
Auto Trait Implementations§
impl Freeze for TableConstraint
impl RefUnwindSafe for TableConstraint
impl Send for TableConstraint
impl Sync for TableConstraint
impl Unpin for TableConstraint
impl UnsafeUnpin for TableConstraint
impl UnwindSafe for TableConstraint
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more