SeaQL / sea-orm

🐚 An async & dynamic ORM for Rust
https://www.sea-ql.org/SeaORM/
Apache License 2.0
7.3k stars 513 forks source link

Migration with enum broke with 0.10.0 #1150

Closed BlinkyStitt closed 2 years ago

BlinkyStitt commented 2 years ago

Description

With 0.9, I had an enum in my migration defined with simple strings:

.col(
    ColumnDef::new(SecondaryUser::Role)
        .enumeration("role", ["owner", "admin", "collaborator"])
        .not_null(),
)

With 0.10, I get this error:

error[E0277]: the trait bound `&str: DeriveIden` is not satisfied
   --> migration/src/m20220101_000001_create_table.rs:59:42
    |
59  | ...                   .enumeration("role", ["owner", "admin", "collaborator"])
    |                        ----------- ^^^^^^ the trait `DeriveIden` is not implemented for `&str`
    |                        |
    |                        required by a bound introduced by this call
    |
    = help: the following other types implement trait `DeriveIden`:
              Alias
              Entity
              Font
              Glyph
              Identity
              NullAlias
              SecondaryUser
              SelectA
            and 34 others
    = note: required because of the requirements on the impl of `IntoIden` for `&str`
note: required by a bound in `sea_orm_migration::prelude::ColumnDef::enumeration`
   --> /home/bryan/.cargo/registry/src/github.com-1ecc6299db9ec823/sea-query-0.27.1/src/table/column.rs:543:12
    |
543 |         N: IntoIden,
    |            ^^^^^^^^ required by this bound in `sea_orm_migration::prelude::ColumnDef::enumeration`

error[E0277]: the trait bound `&str: DeriveIden` is not satisfied
   --> migration/src/m20220101_000001_create_table.rs:59:50
    |
59  | ...                   .enumeration("role", ["owner", "admin", "collaborator"])
    |                        -----------         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `DeriveIden` is not implemented for `&str`
    |                        |
    |                        required by a bound introduced by this call
    |
    = help: the following other types implement trait `DeriveIden`:
              Alias
              Entity
              Font
              Glyph
              Identity
              NullAlias
              SecondaryUser
              SelectA
            and 34 others
    = note: required because of the requirements on the impl of `IntoIden` for `&str`
note: required by a bound in `sea_orm_migration::prelude::ColumnDef::enumeration`
   --> /home/bryan/.cargo/registry/src/github.com-1ecc6299db9ec823/sea-query-0.27.1/src/table/column.rs:544:12
    |
544 |         S: IntoIden,
    |            ^^^^^^^^ required by this bound in `sea_orm_migration::prelude::ColumnDef::enumeration`

Steps to Reproduce

  1. Make an enum using &str like I did above.

Expected Behavior

The migration should compile

Actual Behavior

I get an error: ^ the trait 'DeriveIden' is not implemented for '&str'

Reproduces How Often

100% of the time

Versions

Changing from 0.9.3 to 0.10.0

Additional Information

This looks similar to #1143 (which also got in my way).

BlinkyStitt commented 2 years ago

For now, I wrapped the enum values in Alias::new

.col(
    ColumnDef::new(SecondaryUser::Role)
        .enumeration(
            Alias::new("role"),
            [
                Alias::new("owner"),
                Alias::new("admin"),
                Alias::new("collaborator"),
            ],
        )
        .not_null(),
tyt2y3 commented 2 years ago

I think this is an intended change as explained in the change log.

https://github.com/SeaQL/sea-orm/blob/master/CHANGELOG.md#breaking-changes

BlinkyStitt commented 2 years ago

The breaking change was documented. But the way to migrate to the new format isn't. I think an example of wrapping the &str with Alias::new would be helpful. Maybe under the "then" and "now" sections

tyt2y3 commented 2 years ago

Yes. I think the recommended way is to have a enum and derive Iden on it. Let me find an example