stack/packages/stack-server/prisma/seed.ts
Stan Wohlwend 9ff2cff5c5
Organizations & RBAC (#22)
* added organizations route

* added orgganizations/[orgId] and orgganizations/[orgId]/users routes

* added more routes

* restructured dashboard pages, added organization page

* fixed redirect bug

* updated sidebar

* added mock orgnizations

* fixed breadcrumbs

* added edit org modal

* added memeber table

* added permission table

* Orgs & perms backend

* Fix build errors

* updated permission ui

* org -> team for frontend

* added enable team UI

* Stack App for teams

* formatted schema

* renamed all orgs to teams

* fixed docusaurus bug

* disabled docusaurus build progress bar

* added member profile and direct permission to profile

* removed dead code, memberProfile -> member

* removed teams attribute from the user object

* added /teams endpoint

* added create team endpoint

* added add-user endpoint

* moved add-user

* added server side get teams

* updated schema formatting

* added team enabled endpoints

* fixed type error

* moved get current teams to current-user/teams

* improved interface

* added create team

* hooked up team to frontend

* added hooked up team name with team member page

* added list team users

* added useUsers to team object

* fixed list team user bug

* added team update

* added list permissions and use permission on app

* added create permission

* list permission

* added permission list

* added inherited permission list

* add edit permission model

* restructured permission graph

* updated style

* added delete permission

* fixed delete permission bug

* added inheritence update

* fixed await bug

* fixed selection bug

* added permission update

* fixed update bug

* fixed team update refresh

* added remove user from team

* restructured permission and permission definition

* updated permission definition structure

* updated list permissions and grant permissions

* fixed list user permissions

* added grant permission

* fixed list permission

* added direct option to list team use permission

* fixed bugs

* fixed bugs

* added revoke permission

* inherited from -> contains

* added client list permission

* restructured stack-app teams and permissions

* fixed server teams and permissions

* fixed bug

* fixed bugs

* added teams pages to demo

* added styled component compiler

* added list teams

* added join and leave teams

* fixed prisma onDelete

* fixed type bugs

* removed on permission change for now

* added member

* fixed user and server user

* fixed imports

* added create team

* added more content to demo

* fixed recursion bug

* fixed recursion stack out of bound bug

* removed teamsEnabled

* added create team on sign-up options

* added create team on signup

* queriable -> queryable, fixed migration file

* fixed migration file

* fixed demo build error

* fixed license accidental change

* fixed tab styling

* added required to create permission id

* added more ui error hints

* fixed seed wrong setting

* default team name

* improved permission list ui

* improved demo display

* Update README.md

---------

Co-authored-by: Zai Shi <zaishi00@outlook.com>
2024-05-08 12:43:56 +02:00

78 lines
2.2 KiB
TypeScript

import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
async function seed() {
console.log('Seeding database...');
const oldProjects = await prisma.project.findUnique({
where: {
id: 'internal',
},
});
if (oldProjects) {
console.log('Internal project already exists, skipping seeding');
return;
}
await prisma.project.upsert({
where: {
id: 'internal',
},
create: {
id: 'internal',
displayName: 'Stack Dashboard',
description: 'This project is used for Stack\'s internal dashboard',
isProductionMode: false,
apiKeySets: {
create: [{
description: "Internal API key set",
publishableClientKey: process.env.NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY ?? require('crypto').randomBytes(8).toString("hex"),
secretServerKey: process.env.STACK_SECRET_SERVER_KEY ?? require('crypto').randomBytes(8).toString("hex"),
expiresAt: new Date('2099-12-31T23:59:59Z'),
}],
},
config: {
create: {
allowLocalhost: true,
oauthProviderConfigs: {
create: (['github', 'facebook', 'google', 'microsoft'] as const).map((id) => ({
id,
proxiedOAuthConfig: {
create: {
type: id.toUpperCase() as any,
}
},
projectUserOAuthAccounts: {
create: []
}
})),
},
emailServiceConfig: {
create: {
senderName: 'Internal Project',
proxiedEmailServiceConfig: {
create: {}
}
}
},
credentialEnabled: true,
magicLinkEnabled: true,
createTeamOnSignUp: false,
},
},
},
update: {},
});
console.log('Internal project created');
console.log('Seeding complete!');
}
seed().catch(async (e) => {
console.error(e);
await prisma.$disconnect();
process.exit(1);
// eslint-disable-next-line @typescript-eslint/no-misused-promises, @typescript-eslint/return-await
}).finally(async () => await prisma.$disconnect());