Skip to content

Commit

Permalink
add instructions for customising Role and Permission seeds
Browse files Browse the repository at this point in the history
  • Loading branch information
devneill committed Sep 12, 2024
1 parent 322469a commit fc169d2
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion prisma/migrations/20230914194400_init/migration.sql
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,53 @@ CREATE INDEX "_RoleToUser_B_index" ON "_RoleToUser"("B");
-- Hey there, Kent here! This is how you can reliably seed your database with
-- some data. You edit the migration.sql file and that will handle it for you.

-- The user Roles and Permissions are seeded here.
-- If you'd like to customise roles and permissions, you can edit and add the code below to your `prisma/seed.ts` file.
-- Seed your development database with `npx prisma db seed`
-- Create a sql dump of your database with `sqlite3 prisma/data.db .dump > seed.sql`
-- Replace the SQL below with your new Roles & Permissions related SQL from `seed.sql`

-- console.time('🔑 Created permissions...')
-- const entities = ['user', 'note']
-- const actions = ['create', 'read', 'update', 'delete']
-- const accesses = ['own', 'any'] as const

-- let permissionsToCreate = []
-- for (const entity of entities) {
-- for (const action of actions) {
-- for (const access of accesses) {
-- permissionsToCreate.push({ entity, action, access })
-- }
-- }
-- }
-- await prisma.permission.createMany({ data: permissionsToCreate })
-- console.timeEnd('🔑 Created permissions...')

-- console.time('👑 Created roles...')
-- await prisma.role.create({
-- data: {
-- name: 'admin',
-- permissions: {
-- connect: await prisma.permission.findMany({
-- select: { id: true },
-- where: { access: 'any' },
-- }),
-- },
-- },
-- })
-- await prisma.role.create({
-- data: {
-- name: 'user',
-- permissions: {
-- connect: await prisma.permission.findMany({
-- select: { id: true },
-- where: { access: 'own' },
-- }),
-- },
-- },
-- })
-- console.timeEnd('👑 Created roles...')

INSERT INTO Permission VALUES('clnf2zvli0000pcou3zzzzome','create','user','own','',1696625465526,1696625465526);
INSERT INTO Permission VALUES('clnf2zvll0001pcouly1310ku','create','user','any','',1696625465529,1696625465529);
INSERT INTO Permission VALUES('clnf2zvll0002pcouka7348re','read','user','own','',1696625465530,1696625465530);
Expand Down Expand Up @@ -208,4 +255,4 @@ INSERT INTO _PermissionToRole VALUES('clnf2zvlo0006pcouyoptc5jp','clnf2zvlx000hp
INSERT INTO _PermissionToRole VALUES('clnf2zvlp0008pcou9r0fhbm8','clnf2zvlx000hpcou5dfrbegs');
INSERT INTO _PermissionToRole VALUES('clnf2zvlq000apcouxnspejs9','clnf2zvlx000hpcou5dfrbegs');
INSERT INTO _PermissionToRole VALUES('clnf2zvlr000cpcouy1vp6oeg','clnf2zvlx000hpcou5dfrbegs');
INSERT INTO _PermissionToRole VALUES('clnf2zvls000epcou4ts5ui8f','clnf2zvlx000hpcou5dfrbegs');
INSERT INTO _PermissionToRole VALUES('clnf2zvls000epcou4ts5ui8f','clnf2zvlx000hpcou5dfrbegs');

0 comments on commit fc169d2

Please sign in to comment.