Skip to content
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

Unable to create new table with camel case enum type field using sea-orm-cli migrate #2405

Open
moyuwangP opened this issue Oct 29, 2024 · 0 comments

Comments

@moyuwangP
Copy link

Description

I am using DeriveIden to rename postgresql enum to camel case. I was able to create the Enum type correctly. But manager.create_table spat an error complaining my enum type(in lowercase) does not exist.

Steps to Reproduce

  1. create a migration
  2. run sea-orm-cli -v migrate up
  3. error message occurs
  4. exam the migration log and see that enum type name in create table statement is not wrapped by double quote.

Actual Behavior

enum type name in create table statement is not wrapped by double quote.

CREATE TABLE IF NOT EXISTS "test_table" ("id" serial NOT NULL PRIMARY KEY, "test_enum" TestEnum)

Expected Behavior

enum type name in create table statement should be wrapped by double quote.

CREATE TABLE IF NOT EXISTS "test_table" ("id" serial NOT NULL PRIMARY KEY, "test_enum" "TestEnum")

Reproduces How Often

whenever creating table with camel case enum type

Reproducible Example

...
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .create_type(
                Type::create()
                    .as_enum(TestEnum)
                    .values(TestEnumVariants::iter())
                    .to_owned(),
 )
            .await?;

        manager
            .create_table(
                Table::create()
                    .table(TestTable::Table)
                    .if_not_exists()
                    .col(pk_auto(TestTable::Id))
                    .col(
                        ColumnDef::new(TestTable::TestEnum)
                            .enumeration(TestEnum, TestEnumVariants::iter()),
 )
                    .to_owned(),
 )
            .await
 }
...
#[derive(DeriveIden)]
enum TestTable {
    Table,
    Id,
    TestEnum,
}

#[derive(DeriveIden)]
#[sea_orm(iden = "TestEnum")]
struct TestEnum;

#[derive(DeriveIden, EnumIter)]
enum TestEnumVariants {
    A,
    B,
}
...
2024-10-29T15:49:05.326486Z  INFO sqlx::postgres::notice: relation "seaql_migrations" already exists, skipping
2024-10-29T15:49:05.327650Z  INFO sqlx::query: summary="CREATE TABLE IF NOT …" db.statement="\n\nCREATE TABLE IF NOT EXISTS \"seaql_migrations\" (\n  \"version\" varchar NOT NULL PRIMARY KEY,\n  \"applied_at\" bigint NOT NULL\n)\n" rows_affected=0 rows_returned=0 elapsed=7.675334ms elapsed_secs=0.007675334
2024-10-29T15:49:05.327716Z  INFO sea_orm_migration::migrator: Applying all pending migrations
2024-10-29T15:49:05.330810Z  INFO sqlx::postgres::notice: relation "seaql_migrations" already exists, skipping
2024-10-29T15:49:05.331607Z  INFO sqlx::query: summary="CREATE TABLE IF NOT …" db.statement="\n\nCREATE TABLE IF NOT EXISTS \"seaql_migrations\" (\n  \"version\" varchar NOT NULL PRIMARY KEY,\n  \"applied_at\" bigint NOT NULL\n)\n" rows_affected=0 rows_returned=0 elapsed=3.085167ms elapsed_secs=0.003085167
2024-10-29T15:49:05.334122Z  INFO sqlx::postgres::notice: relation "seaql_migrations" already exists, skipping
2024-10-29T15:49:05.334960Z  INFO sqlx::query: summary="CREATE TABLE IF NOT …" db.statement="\n\nCREATE TABLE IF NOT EXISTS \"seaql_migrations\" (\n  \"version\" varchar NOT NULL PRIMARY KEY,\n  \"applied_at\" bigint NOT NULL\n)\n" rows_affected=0 rows_returned=0 elapsed=2.508959ms elapsed_secs=0.002508959
2024-10-29T15:49:05.338076Z  INFO sqlx::postgres::notice: relation "seaql_migrations" already exists, skipping
2024-10-29T15:49:05.338877Z  INFO sqlx::query: summary="CREATE TABLE IF NOT …" db.statement="\n\nCREATE TABLE IF NOT EXISTS \"seaql_migrations\" (\n  \"version\" varchar NOT NULL PRIMARY KEY,\n  \"applied_at\" bigint NOT NULL\n)\n" rows_affected=0 rows_returned=0 elapsed=3.036208ms elapsed_secs=0.003036208
2024-10-29T15:49:05.348089Z  INFO sqlx::query: summary="SELECT \"version\", \"applied_at\" FROM …" db.statement="\n\nSELECT\n  \"version\",\n  \"applied_at\"\nFROM\n  \"seaql_migrations\"\nORDER BY\n  \"version\" ASC\n" rows_affected=0 rows_returned=0 elapsed=8.770958ms elapsed_secs=0.008770958
2024-10-29T15:49:05.348180Z  INFO sea_orm_migration::migrator: Applying migration 'm20220101_000001_create_table'
2024-10-29T15:49:05.357283Z  INFO sqlx::query: summary="CREATE TYPE \"TestEnum\" AS …" db.statement="\n\nCREATE TYPE \"TestEnum\" AS ENUM ('a', 'b')\n" rows_affected=0 rows_returned=0 elapsed=8.688584ms elapsed_secs=0.008688584
2024-10-29T15:49:05.364974Z  INFO sqlx::query: summary="CREATE TABLE IF NOT …" db.statement="\n\nCREATE TABLE IF NOT EXISTS \"test_table\" (\n  \"id\" serial NOT NULL PRIMARY KEY,\n  \"test_enum\" TestEnum\n)\n" rows_affected=0 rows_returned=0 elapsed=6.936ms elapsed_secs=0.006936
Execution Error: error returned from database: type "testenum" does not exist
Fail to run migration

Version

sea-orm-cli 1.1.0

 > cargo tree |grep sea-  
└── sea-orm-migration v1.1.0
    ├── sea-orm v1.1.0
    │   ├── sea-orm-macros v1.1.0 (proc-macro)
    │   │   ├── sea-bae v0.2.1 (proc-macro)
    │   ├── sea-query v0.32.0
    │   │   └── sea-query-derive v0.4.2 (proc-macro)
    │   ├── sea-query-binder v0.7.0
    │   │   ├── sea-query v0.32.0 (*)
    ├── sea-orm-cli v1.1.0
    │   ├── sea-schema v0.16.0
    │   │   ├── sea-query v0.32.0 (*)
    │   │   └── sea-schema-derive v0.3.0 (proc-macro)
    ├── sea-schema v0.16.0 (*)
>postgres -V
postgres (PostgreSQL) 14.13 (Ubuntu 14.13-0ubuntu0.22.04.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant