Skip to content

rename_to() error  #1995

@Mohan-sharma-Venkatesh

Description

@Mohan-sharma-Venkatesh

Description

  1. rename_to() error
    The rename_to() function of struct
    Struct sea_orm_migration::manager::SchemaManager
    produces an error. The rename_to() is a function used to rename the Type.
    But produces an error because it is not able to generate the SQL statement with double quotes
    --> It produces the SQL statement with single quotes

Steps to Reproduce

  1. Seo orm version and information in cargo.toml
sea-orm = { version = "0.12.0", features = [ "with-chrono", "sqlx-postgres", "runtime-async-std-native-tls", "macros" ] }

Postgres DB version = 6.19

  1. Create a migrations file with the name alter_type.rs using the terminal command
sea-orm-cli migrate generate "alter_type"

  1. paste the code below
use crate::extension::postgres::Type;
use sea_orm_migration::prelude::*;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        let create_type = Type::create()
            .as_enum(Number::Number)
            .values([Number::One, Number::Two])
            .to_owned();
        dbg!(create_type.to_string(PostgresQueryBuilder));
        manager.create_type(create_type).await
    }

    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        let alter_type_name = Type::alter()
            .name(Number::Number)
            .rename_to(RenameType::Phonenumber); //This will create an error because of rename_to()
        dbg!(alter_type_name.to_string(PostgresQueryBuilder));
        manager.alter_type(alter_type_name).await
        // This below lines are raw query will work perfectly and rename type
        // let raw_rename_type = r#"
        // ALTER TYPE number RENAME TO phonenumber;
        // "#;
        // manager
        //     .get_connection()
        //     .execute_unprepared(raw_rename_type)
        //     .await?;
        // Ok(())
    }
}

#[derive(DeriveIden)]
enum Number {
    Number,
    One,
    Two,
}

#[derive(DeriveIden)]
enum RenameType {
    Phonenumber,
}
  1. Then run a fresh migration command in the terminal
DATABASE_URL="url" sea-orm-cli migrate fresh 

  1. After fresh is successfully migrate Down using terminal
DATABASE_URL="url" sea-orm-cli migrate down

  1. This will create an error
    Screenshot 2023-12-05 at 13 19 53

  2. If you run only the raw query then the migration will run and rename the Type without any error

  3. This states that there is an error near 'phonenumber'

Expected Behavior

This rename_to() function must generate SQL command

ALTER TYPE "number" RENAME TO "phonenumber"

Actual Behavior

This remate_to() function actually generates

ALTER TYPE "number" RENAME TO 'phonenumber'

Difference is

'phonenumber' --> generated [This is produce the error]
"phonenumber" --> expected [This will work perfectly]

Must have generate " " instead of ' '

Reproduces How Often

This happens whenever you use the rename_to() function

Workarounds

Must have generated " " instead of ' '

Reproducible Example

Versions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions