I’m migrating data to prisma2/postgres. How can i ...
# orm-help
z
I’m migrating data to prisma2/postgres. How can i force a model to create an ID on existing content? (i have my old mongoids already as a different column but i want to start using prisma uuids)
r
@zebapy 👋 When doing this with Migrate, you would need to create a new field and then update that to use UUID’s in the
.sql
migration file as follows:
Copy code
UPDATE "my_table" SET "uuid_column" = generate_uuid();
So the steps you would need to take is: 1. Create the field 2. Populate the field with UUID’s 3. Set it as the primary key after all rows are populated
🙏 1
a
Hello @zebapy, if you are happy to have the DB generate the UUIDs instead of Prisma this would be much less work, since the DB will take care of populating the column for all existing rows. Add a new field named id of type UUID and set the default to DB-level UUIDs:
Copy code
id   String  @id @db.Uuid @default(dbgenerated("gen_random_uuid()"))
Note: requires the
pgcrypto
extension.
plus one +1 1
z
Thanks all! I ended up generating a UUID with node
uuid
package as I’m doing some data grooming / creating csv files from node, which then get imported directly without prisma at that time
👍 1