Closed Thijmen closed 1 week ago
Hey @Thijmen, there are 2 ways It seems like on the migration create prompt you choosed "rename the column", which looks like can't be done with Drizzle for now. You can choose to drop the previous column and add new, you'll lose the existing data in this column though.
Another way is to modify the SQL script in the migration accordingly so that it properly adds this column without losing the data. This could work:
ALTER TABLE "nav_links" ALTER COLUMN "icon" SET DATA TYPE enum_nav_links_icon USING "icon"::enum_nav_links_icon;
But you need to ensure that all your current icons values are within the enum values range.
Hi @r1tsuu,
This is the full script now;
export async function up({ payload, req }: MigrateUpArgs): Promise<void> {
await payload.db.drizzle.execute(sql`
DO $$ BEGIN
CREATE TYPE "public"."enum_nav_links_icon" AS ENUM('home', 'project', 'dashboard', 'blog', 'profile', 'analytics');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
UPDATE "nav_links" SET "icon" = 'home';
ALTER TABLE "nav_links" ALTER COLUMN "icon" SET DATA TYPE enum_nav_links_icon USING "icon"::enum_nav_links_icon;
ALTER TABLE "nav_links" ALTER COLUMN "icon" SET NOT NULL;`)
}
I cant recall that I've used 'rename the column`, but this is fine now! :) Just wanted to make sure if this was expected or not.
This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.
Link to reproduction
No response
Environment Info
Describe the Bug
So, I have a global that looks like this:
I create a migration for Postgresql, and it looks like this:
Then I've decided to make the icon a list item:
That will result in a migration that looks like this:
Now, this will not be able to run because of the following error:
I am no postgresql guru at all, so I thought: okay, maybe there's some value in the database which does not meet the values allowed. So, I added a little sql part:
Unfortunately this does not work either.
I am unsure if this is a bug or expected behaviour.
Reproduction Steps
See steps above
Adapters and Plugins
db-postgres