ariga / atlas

Manage your database schema as code
https://atlasgo.io
Apache License 2.0
5.94k stars 265 forks source link

Planner creates failing ALTER COLUMN for column changing from int to enum #3130

Open dolzenko opened 1 month ago

dolzenko commented 1 month ago

I'm using atlas schema apply with 2 DBs, one has the column lang_code defined as TEXT another as ENUM, so Atlas generates the ALTER TABLE but it can't proceed. Is that a bug in convergence code?

  -- modify "characteristics_localization" table
    -> ALTER TABLE "public"."characteristics_localization" ALTER COLUMN "lang_code" TYPE "public"."lang_code";
    pq: column "lang_code" cannot be cast automatically to type lang_code

  -------------------------
  -- 24.95230433s
  -- 1 migration with errors
  -- 16 sql statements ok, 1 with errors
Error: executing statement "ALTER TABLE \"public\".\"characteristics_localization\" ALTER COLUMN \"lang_code\" TYPE \"public\".\"lang_code\";": pq: column "lang_code" cannot be cast automatically to type lang_code

What I mean by that is that it could easily see that this won't work and warn me some time earlier on, or is it by design?

a8m commented 1 month ago

Hey @dolzenko!

The planner can be smarter here, by adding pre-migration checks and let you control the type conversion. For now, I'll suggest you to run schema apply with the --edit flag and modify this statement.

I'll keep this issue open and assign it to myself.