#[non_exhaustive]pub enum CheckViolationStrategy {
NullifyViolatingColumn {
column: ColumnName,
},
DeleteViolatingRows,
}Expand description
How AddConstraint(Check) should handle pre-existing rows that
violate the CHECK predicate.
“Violation” is computed statically by the narrow-shape parser in
vespertide-planner::validate::check_default and the cleanup SQL is
emitted by vespertide-query::sql::add_constraint::check. CHECK
expressions that exceed the narrow shape (function calls, AND/OR
composition, subqueries) are not covered by either side ? the
detector skips them and no pre-cleanup is emitted.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
NullifyViolatingColumn
Set the named column of every violating row to NULL ahead of
the ADD CONSTRAINT. The row is preserved; only the failing
value is cleared.
Only applicable when column is nullable in the baseline; the
SQL generator emits a runtime SQL error otherwise (UPDATE …
SET col = NULL violates the existing NOT NULL). The revision
CLI’s narrow-shape parser identifies the target column
automatically; the user rarely sets this directly in the model
JSON.
Fields
column: ColumnNameWhich column receives SET = NULL. Narrow-shape CHECKs
always reduce to a single column, so this is the only
column the cleanup affects.
DeleteViolatingRows
Delete the violating rows outright ahead of the
ADD CONSTRAINT. Use when the violating rows are themselves
invalid (logically dangling records).
This is also the canonical default for the wire format: v0.1.x
models carry no strategy field and so deserialize to
DeleteViolatingRows. The revision CLI re-prompts for an
explicit choice, and the prompt offers
NullifyViolatingColumn { column } when the narrow-shape
parser can identify a nullable target column.
Trait Implementations§
Source§impl Clone for CheckViolationStrategy
impl Clone for CheckViolationStrategy
Source§fn clone(&self) -> CheckViolationStrategy
fn clone(&self) -> CheckViolationStrategy
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 CheckViolationStrategy
impl Debug for CheckViolationStrategy
Source§impl Default for CheckViolationStrategy
impl Default for CheckViolationStrategy
Source§fn default() -> Self
fn default() -> Self
Default strategy is DeleteViolatingRows. Unlike F3
(NullifyOrphans), F4 cannot default to the less destructive
NullifyViolatingColumn because that variant requires a
column argument the wire-format default cannot supply
(CHECK expressions are free-form text and the column name has
to be parsed out by vespertide-planner).
Wire-format note. v0.1.x emitted no pre-cleanup at all and
let the database reject the migration. v0.2 emits
DELETE FROM table WHERE NOT (<expr>) automatically. Existing
migrations that already applied under v0.1.x are unaffected
(apply happens once); v0.1.x migrations re-run against a
fresh DB will now drop violating rows instead of failing. The
revision CLI prompts for an explicit choice on every new
AddConstraint(Check), so production usage rarely hits the
default - it exists for v0.1.x compatibility only.
Source§impl<'de> Deserialize<'de> for CheckViolationStrategy
impl<'de> Deserialize<'de> for CheckViolationStrategy
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 CheckViolationStrategy
Source§impl Hash for CheckViolationStrategy
impl Hash for CheckViolationStrategy
Source§impl JsonSchema for CheckViolationStrategy
impl JsonSchema for CheckViolationStrategy
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 CheckViolationStrategy
impl Ord for CheckViolationStrategy
Source§fn cmp(&self, other: &CheckViolationStrategy) -> Ordering
fn cmp(&self, other: &CheckViolationStrategy) -> 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 CheckViolationStrategy
impl PartialEq for CheckViolationStrategy
Source§fn eq(&self, other: &CheckViolationStrategy) -> bool
fn eq(&self, other: &CheckViolationStrategy) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialOrd for CheckViolationStrategy
impl PartialOrd for CheckViolationStrategy
Source§impl Serialize for CheckViolationStrategy
impl Serialize for CheckViolationStrategy
impl StructuralPartialEq for CheckViolationStrategy
Auto Trait Implementations§
impl Freeze for CheckViolationStrategy
impl RefUnwindSafe for CheckViolationStrategy
impl Send for CheckViolationStrategy
impl Sync for CheckViolationStrategy
impl Unpin for CheckViolationStrategy
impl UnsafeUnpin for CheckViolationStrategy
impl UnwindSafe for CheckViolationStrategy
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