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

Alter enum column with new type (missing USING) #2231

Open
zezic opened this issue May 20, 2024 · 0 comments
Open

Alter enum column with new type (missing USING) #2231

zezic opened this issue May 20, 2024 · 0 comments

Comments

@zezic
Copy link

zezic commented May 20, 2024

Description

When trying to alter column of enum type to make it use the new enum type I'm getting a error from Postgres saying:

[1642] LOG:  execute sqlx_s_4: ALTER TABLE "fact" ALTER COLUMN "kind" TYPE fact_kind, ALTER COLUMN "kind" SET NOT NULL
[1642] ERROR:  column "kind" cannot be cast automatically to type fact_kind
[1642] HINT:  You might need to specify "USING kind::fact_kind".

The part of migration causing this error looks like that:

        manager
            .alter_table(
                Table::alter()
                    .table(m20240307_074314_create_fact_table::Fact::Table)
                    .modify_column(
                        ColumnDef::new(m20240307_074314_create_fact_table::Fact::Kind)
                            .enumeration(FactKindEnum, FactKind::iden_values())
                            .not_null(),
                    )
                    .to_owned(),
            )
            .await?;

Steps to Reproduce

  1. Using PostgreSQL as backend run migration to prepare table with some enum column.
  2. Using another migration try to alter that column and convert it to other (for example, extended version of previous) enum type.
  3. PostgreSQL will say that expression is missing the USING clause.

Expected Behavior

Expected ColumnDef to be able to generate statement which includes the extra USING clause followed with explicit column and its type – https://www.postgresql.org/docs/current/ddl-alter.html#DDL-ALTER-COLUMN-TYPE , or optionally followed by expression column_name::text::type_name to use thru-text cast.

Actual Behavior

The SQL appears to be generated without USING clause (PostgreSQL refuses to convert existing data to implicit type without it).

Reproduces How Often

Reproduced always.

Workarounds

Write raw SQL by hand.

Versions

sea-orm-migration 0.12.15

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