Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sea-orm-cli generate entity migration select_as, save_as support #1643

Closed
GoodLucky777 opened this issue May 16, 2023 · 0 comments · May be fixed by #2081
Closed

sea-orm-cli generate entity migration select_as, save_as support #1643

GoodLucky777 opened this issue May 16, 2023 · 0 comments · May be fixed by #2081

Comments

@GoodLucky777
Copy link

Motivation

I was trying to make Postgresql citext column with migration and generate entity with sea-orm-cli generate entity.

Migration up:

manager
    .get_connection()
    .execute_unprepared("CREATE EXTENSION IF NOT EXISTS citext")
    .await?;

manager
    .create_table(
        Table::create()
            .table(User::Table)
            .if_not_exists()
            .col(ColumnDef::new(User::Id).uuid().not_null().primary_key())
             .col(
                 ColumnDef::new(User::Email)
                    .custom(Alias::new("citext"))
                    .not_null()
                    .unique_key(),
              )
              .to_owned(),
          )
          .await?;

sea-orm-cli generate entity -o src/entity generates:

//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3

use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "user")]
pub struct Model {
    #[sea_orm(primary_key, auto_increment = false)]
    pub id: Uuid,
    #[sea_orm(column_type = "custom(\"citext\")", unique)]
    pub email: String,
}

When I try to select the user, this error occurs:

DatabaseError occurred: Query Error: error occurred while decoding column "email": mismatched types; Rust type `core::option::Option<alloc::string::String>` (as SQL type `TEXT`) is not compatible with SQL type `citext`

If I edit the entity to this the error doesn't occurs:

#[sea_orm(column_type = "custom(\"citext\")", select_as = "text", save_as = "citext", unique)]
pub email: String

Proposed Solutions

Able to set select_as, save_as in migration.

Current Workarounds

Edit the entity manually when I generate it.

@SeaQL SeaQL locked and limited conversation to collaborators May 17, 2023
@tyt2y3 tyt2y3 converted this issue into discussion #1657 May 17, 2023
lucasmerlin added a commit to lucasmerlin/sea-orm that referenced this issue Jan 26, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant