A developer updates the Prisma schema file to include a product model with a one-to-many relationship to users. After defining the fields and relations, the developer runs a migration command and verifies the new table creation within the pgAdmin interface.
Length 6:30
Captions English (Generated), Spanish (Auto-translated), French (Auto-translated), Korean (Auto-translated), Portuguese (Auto-translated), Vietnamese (Auto-translated) #prisma #schema #database #migration #postgresql #programming #backend #development #relational #coding
0:00 Okay, so we're ready to start implementing 0:02 products into our 0:03 application so that we can actually create new products for our 0:07 online store and eventually view them as well. 0:11 So let's go ahead and get started in our back end where we 0:14 know the first 0:15 step is, of course, to make sure our database schema 0:18 is gonna get 0:19 updated to introduce a new table that's going to 0:22 hold these product entities. So let's open up our 0:26 schema Prisma file where we know we have our existing 0:30 model for a user. I wanna create another model now for a 0:33 product which we know Prisma will actually generate a 0:37 migration for to create the underlying table for 0:41 us. 0:42 So let's go ahead and define this new model called Product, 0:47 and this product is again gonna have an ID on it. 0:52 This is gonna be an integer 0:54 where we set the default to just simply auto-increment. 0:58 So just like for the user, I wanna have a unique identifier for each 1:01 and every 1:01 product in our system. Then I want to have a name for the 1:05 product of type string 1:08 as well as a description. So let's add a description that's 1:12 going to be what the product is about. 1:15 Next up, I want to add the price of the product, 1:18 which we'll add as a floating 1:19 point number. 1:21 Finally, I want to add a property on this product 1:25 that's 1:25 actually going to build a relationship to this 1:29 underlying product table to our users table. 1:33 So I want to introduce a one-to-many 1:36 relationship here where a single user can 1:40 have many different underlying products. 1:43 Now, to actually represent this relationship in 1:46 Prisma, we 1:47 firstly need to go ahead and define user 1:51 ID on the actual product. So this is gonna 1:55 be the user's ID field that is associated or
The rest of the transcript is for members.
Sign in