@@ -173,6 +173,53 @@ CREATE INDEX "_RoleToUser_B_index" ON "_RoleToUser"("B");
173173-- Hey there, Kent here! This is how you can reliably seed your database with
174174-- some data. You edit the migration.sql file and that will handle it for you.
175175
176+ -- The user Roles and Permissions are seeded here.
177+ -- If you'd like to customise roles and permissions, you can edit and add the code below to your `prisma/seed.ts` file.
178+ -- Seed your development database with `npx prisma db seed`
179+ -- Create a sql dump of your database with `sqlite3 prisma/data.db .dump > seed.sql`
180+ -- Replace the SQL below with your new Roles & Permissions related SQL from `seed.sql`
181+
182+ -- console.time('🔑 Created permissions...')
183+ -- const entities = ['user', 'note']
184+ -- const actions = ['create', 'read', 'update', 'delete']
185+ -- const accesses = ['own', 'any'] as const
186+
187+ -- let permissionsToCreate = []
188+ -- for (const entity of entities) {
189+ -- for (const action of actions) {
190+ -- for (const access of accesses) {
191+ -- permissionsToCreate.push({ entity, action, access })
192+ -- }
193+ -- }
194+ -- }
195+ -- await prisma.permission.createMany({ data: permissionsToCreate })
196+ -- console.timeEnd('🔑 Created permissions...')
197+
198+ -- console.time('👑 Created roles...')
199+ -- await prisma.role.create({
200+ -- data: {
201+ -- name: 'admin',
202+ -- permissions: {
203+ -- connect: await prisma.permission.findMany({
204+ -- select: { id: true },
205+ -- where: { access: 'any' },
206+ -- }),
207+ -- },
208+ -- },
209+ -- })
210+ -- await prisma.role.create({
211+ -- data: {
212+ -- name: 'user',
213+ -- permissions: {
214+ -- connect: await prisma.permission.findMany({
215+ -- select: { id: true },
216+ -- where: { access: 'own' },
217+ -- }),
218+ -- },
219+ -- },
220+ -- })
221+ -- console.timeEnd('👑 Created roles...')
222+
176223INSERT INTO Permission VALUES (' clnf2zvli0000pcou3zzzzome' ,' create' ,' user' ,' own' ,' ' ,1696625465526 ,1696625465526 );
177224INSERT INTO Permission VALUES (' clnf2zvll0001pcouly1310ku' ,' create' ,' user' ,' any' ,' ' ,1696625465529 ,1696625465529 );
178225INSERT INTO Permission VALUES (' clnf2zvll0002pcouka7348re' ,' read' ,' user' ,' own' ,' ' ,1696625465530 ,1696625465530 );
@@ -208,4 +255,4 @@ INSERT INTO _PermissionToRole VALUES('clnf2zvlo0006pcouyoptc5jp','clnf2zvlx000hp
208255INSERT INTO _PermissionToRole VALUES (' clnf2zvlp0008pcou9r0fhbm8' ,' clnf2zvlx000hpcou5dfrbegs' );
209256INSERT INTO _PermissionToRole VALUES (' clnf2zvlq000apcouxnspejs9' ,' clnf2zvlx000hpcou5dfrbegs' );
210257INSERT INTO _PermissionToRole VALUES (' clnf2zvlr000cpcouy1vp6oeg' ,' clnf2zvlx000hpcou5dfrbegs' );
211- INSERT INTO _PermissionToRole VALUES (' clnf2zvls000epcou4ts5ui8f' ,' clnf2zvlx000hpcou5dfrbegs' );
258+ INSERT INTO _PermissionToRole VALUES (' clnf2zvls000epcou4ts5ui8f' ,' clnf2zvlx000hpcou5dfrbegs' );
0 commit comments