Skip to main content

durable_db/entity/
sea_orm_active_enums.rs

1//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.19
2
3use sea_orm::entity::prelude::*;
4use serde::{Deserialize, Serialize};
5
6#[derive(
7    Debug,
8    Clone,
9    PartialEq,
10    Eq,
11    EnumIter,
12    DeriveActiveEnum,
13    Serialize,
14    Deserialize,
15    strum :: Display,
16    strum :: EnumString,
17)]
18// HACK: The embedded quotes make sea-query's Iden::quoted() produce
19// "durable"."task_status" — a valid schema-qualified PostgreSQL identifier.
20// Without this, SeaORM generates CAST($1 AS "task_status") which fails when
21// the `durable` schema is not in the connection's search_path.
22// Verified against sea-orm 1.x / sea-query 0.32. If a future sea-orm release
23// sanitises Iden strings, this will break — see the assertion test below.
24#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "durable\".\"task_status")]
25#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
26pub enum TaskStatus {
27    #[sea_orm(string_value = "PENDING")]
28    Pending,
29    #[sea_orm(string_value = "RUNNING")]
30    Running,
31    #[sea_orm(string_value = "COMPLETED")]
32    Completed,
33    #[sea_orm(string_value = "FAILED")]
34    Failed,
35    #[sea_orm(string_value = "PAUSED")]
36    Paused,
37    #[sea_orm(string_value = "CANCELLED")]
38    Cancelled,
39}
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44    use sea_orm::ActiveEnum;
45    use sea_orm::sea_query::Iden;
46
47    /// Guard against sea-orm/sea-query changes that would break the
48    /// schema-qualified enum_name hack above.
49    #[test]
50    fn task_status_iden_is_schema_qualified() {
51        let iden = TaskStatus::name();
52        let quoted = iden.to_string();
53        assert_eq!(
54            quoted,
55            r#"durable"."task_status"#,
56            "TaskStatus Iden must render as the unquoted schema-qualified name; \
57             sea-query wraps it to produce \"durable\".\"task_status\" in SQL"
58        );
59    }
60}