Skip to content

Docs for Writing a Migration > Enums | Error + improvements needed #170

@devklick

Description

@devklick

I'm finding that the docs are quite vague and confusing, particularly around creating enums in migrations.

The following blocks of code are taken from:
https://www.sea-ql.org/SeaORM/docs/migration/writing-migration/#schema-creation-methods

First off; is there a typo? One section uses Store for the enum value/variant, and the other uses story? I'm assuming these should be the same.

A table is defined and it contains a column that uses an enum type. It's unclear what enumeration or enumeration_null actually does. My initial thought was that this creates the postgres enum type and assigns it to the column, but it doesnt. I now think that the first parameter is the column name, the second is the name of the postgres enum (which needs to be created separately), and the third parameter is the enum members/variants to generate on the generated rust enum? Total guess though.

manager
    .create_table(
        Table::create()
            .table("post")
            .if_not_exists()
            .col(pk_auto("id"))
            .col(string("title"))
            .col(string("text"))
            .col(enumeration_null("category", "category", ["Feed", "Store"]))
    )
    .await

There's a separate section to create a postgres enum data type. It's unclear what the relation is between the above section and the below section. It's also unclear what CategoryEnum is - it's not defined anywhere in the docs, so this example does not compile. Is it a rust enum type, does it require certain attributes or macros? Should it be a string? Why are the values different to the enumeration variants mentioned earlier (different case, and Store vs storey (latter is probably a typo))

manager
    .create_type(
        Type::create()
            .as_enum(CategoryEnum)
            .values(["feed", "story"])
            .to_owned()
    )
    .await?;

If both the second block is needed (to create the postgres type) and the second block is needed (to create a column that uses the type), do we really need to duplicate the values/variants? I cant get my head around why we need to specify the variants when calling enumeration_null if we're specifying the name of the type that it uses - surely they can (and should) be inferred from the type, rather than duplicated whenever we reference that type?

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions