-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(prisma-seeds): ✨ configure seeds for prisma and add a singleton …
…prisma object configure script to seed data for prisma in the prisma/seed and create a prisma singleton in lib, and add an example for usage in the main page closes #27
- Loading branch information
Showing
7 changed files
with
59 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { PrismaClient } from '@prisma/client' | ||
|
||
const prisma = new PrismaClient() | ||
|
||
async function main() { | ||
const user = await prisma.user.upsert({ | ||
where: { email: 'test@test.com' }, | ||
update: {}, | ||
create: { | ||
email: 'test@test.com', | ||
name: 'Test User', | ||
password: `$2y$12$GBfcgD6XwaMferSOdYGiduw3Awuo95QAPhxFE0oNJ.Ds8qj3pzEZy` | ||
} | ||
}) | ||
console.log({ user }) | ||
} | ||
main() | ||
.then(() => prisma.$disconnect()) | ||
.catch(async (e) => { | ||
console.error(e) | ||
await prisma.$disconnect() | ||
process.exit(1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import NextAuth from 'next-auth' | ||
|
||
import { authOptions } from '@/app/lib/auth' | ||
import { authOptions } from '@/lib/auth' | ||
|
||
const handler = NextAuth(authOptions) | ||
export { handler as GET, handler as POST } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Create a singleton for prisma client | ||
import { PrismaClient } from '@prisma/client' | ||
|
||
// PrismaClient is attached to the `global` object in development to prevent | ||
// exhausting your database connection limit. | ||
// | ||
// Learn more: | ||
// https://pris.ly/d/help/next-js-best-practices | ||
|
||
const globalForPrisma = global as unknown as { prisma: PrismaClient } | ||
|
||
export const prisma = | ||
globalForPrisma.prisma || | ||
new PrismaClient({ | ||
log: ['query'] | ||
}) | ||
|
||
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma |