-
-
Notifications
You must be signed in to change notification settings - Fork 228
Open
Labels
Description
What I'm trying to do:
CREATE TYPE my_composite_struct AS (code_type TEXT, reference_code INT);
CREATE TABLE demo_tb (id SERIAL PRIMARY KEY, composite_field my_composite_struct);I couldn't find any way to do this in my migrations. What I need is a (rough) equivalent of how we create enum types in the following code, but instead for creating composite types:
use sea_orm_migration::prelude::*;
use sea_orm_migration::sea_query::extension::postgres::Type;
#[derive(Iden)]
pub enum KycStatus {
#[iden = "kyc_status"]
Type,
Pending,
Approved,
}
impl KycStatus {
pub const fn list_variants() -> [KycStatus; 2] {
[KycStatus::Pending, KycStatus::Approved]
}
}
pub struct Migration;
// ...
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let mut create_kyc_status_enum = Type::create();
create_kyc_status_enum.as_enum(KycStatus::Type).values(KycStatus::list_variants());
manager.create_type(create_kyc_status_enum).await?;
// ...
Ok(())
}
// ...
}Digging a little bit, I found this commented variant of TypeAs enum:
sea-query/src/extension/postgres/types.rs
Line 63 in 3cb9247
| // Composite, |
Let me know, if there are any existing solutions for this.
Originally posted by @PreetamSing in #612