SeaQL / SeaQL/sea-orm

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

Open
#2,405 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help-wanted
Dominant language
Rust
Stars
9.9k
Forks
735
Avg merge
6h 36m
Merged PRs (30d)
8

Description

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the shown migration against PostgreSQL, then trace Table::create and ColumnDef::new(...).enumeration(...) through the generated CREATE TABLE SQL. Done means a camel-case enum type is quoted in the statement and the migration succeeds; add coverage if the repository’s existing tests provide a suitable entry point.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, rust
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.