© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
49 replies
Eddy Vinck

Drizzle schema vs SQL when migrating serial id to uuid?

I have a Postgres DB and I want to migrate serial primary key IDs to UUIDs, and I'm running into some potential issues here.

I've already added the
uuid
uuid
columns and
user_uuid
user_uuid
,
thing_uuid
thing_uuid
relation columns to my tables via my Drizzle schema. Using PgAdmin I verified that the various
uuid
uuid
columns are not empty, and I've filled the relational UUIDs with queries like this one:

UPDATE user_usage usage SET user_uuid = u.uuid FROM users u WHERE usage.user_id = u.id;
UPDATE user_usage usage SET user_uuid = u.uuid FROM users u WHERE usage.user_id = u.id;


Problem 1:

To prevent having to update my whole application code, I want to basically swap the ID and UUID columns and let them keep the
id
id
and
user_id
user_id
column names, but with
uuid
uuid
primary keys of course.

Is this something I can solve by editing my schema, or would this be something I need to do by running SQL queries?

Problem 2:

If I need to do this via SQL queries, how do I then reflect this new state in my Drizzle schema? Maybe introspecting would be a good option here?

Or maybe I should just change my schema, generate a migration and then edit the migration by hand before running it?

Note: this is a development database migration, so this is essentially practice for whenever I might need to do something similar in prod
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Migrating prisma schema to drizzle
Drizzle TeamDTDrizzle Team / help
3y ago
Changing `id` type from serial to uuid, causing error.
Drizzle TeamDTDrizzle Team / help
2y ago
serial('id').primaryKey() vs primaryKey() in extraConfig?
Drizzle TeamDTDrizzle Team / help
15mo ago
drizzle-kit push ignores SQL schema
Drizzle TeamDTDrizzle Team / help
8mo ago