Skip to main content

Module remap_enum_values

Module remap_enum_values 

Source
Expand description

SQL generator for MigrationAction::RemapEnumValues.

Integer-backed enums in vespertide are stored as plain INTEGER on every supported backend. When the user changes a variant’s numeric value (e.g. medium: 5 → 10), the DB does not detect the drift and the next ORM-side deserialisation silently re-interprets every existing row. This module emits a single atomic UPDATE ... SET col = CASE WHEN ... END WHERE col IN (...) that re-stamps affected rows before the new ORM mapping takes effect.

The SQL is portable across PostgreSQL, MySQL and SQLiteCASE WHEN and IN (...) are universal.

Functions§

build_remap_enum_values
Build a single atomic UPDATE that re-stamps every row whose stored integer value is being remapped. Empty mapping yields Ok(vec![]) so callers can blindly forward zero-change actions without special casing them.