Initial commit
This commit is contained in:
0
scripts/.keep
Normal file
0
scripts/.keep
Normal file
63
scripts/seed.ts
Normal file
63
scripts/seed.ts
Normal file
@ -0,0 +1,63 @@
|
||||
import type { Prisma } from '@prisma/client'
|
||||
import { db } from 'api/src/lib/db'
|
||||
|
||||
export default async () => {
|
||||
try {
|
||||
//
|
||||
// Manually seed via `yarn rw prisma db seed`
|
||||
// Seeds automatically with `yarn rw prisma migrate dev` and `yarn rw prisma migrate reset`
|
||||
//
|
||||
// Update "const data = []" to match your data model and seeding needs
|
||||
//
|
||||
const data: Prisma.UserExampleCreateArgs['data'][] = [
|
||||
// To try this example data with the UserExample model in schema.prisma,
|
||||
// uncomment the lines below and run 'yarn rw prisma migrate dev'
|
||||
//
|
||||
// { name: 'alice', email: 'alice@example.com' },
|
||||
// { name: 'mark', email: 'mark@example.com' },
|
||||
// { name: 'jackie', email: 'jackie@example.com' },
|
||||
// { name: 'bob', email: 'bob@example.com' },
|
||||
]
|
||||
console.log(
|
||||
"\nUsing the default './scripts/seed.{js,ts}' template\nEdit the file to add seed data\n"
|
||||
)
|
||||
|
||||
// Note: if using PostgreSQL, using `createMany` to insert multiple records is much faster
|
||||
// @see: https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#createmany
|
||||
await Promise.all(
|
||||
//
|
||||
// Change to match your data model and seeding needs
|
||||
//
|
||||
data.map(async (data: Prisma.UserExampleCreateArgs['data']) => {
|
||||
const record = await db.userExample.create({ data })
|
||||
console.log(record)
|
||||
})
|
||||
)
|
||||
|
||||
// If using dbAuth and seeding users, you'll need to add a `hashedPassword`
|
||||
// and associated `salt` to their record. Here's how to create them using
|
||||
// the same algorithm that dbAuth uses internally:
|
||||
//
|
||||
// import { hashPassword } from '@redwoodjs/auth-dbauth-api'
|
||||
//
|
||||
// const users = [
|
||||
// { name: 'john', email: 'john@example.com', password: 'secret1' },
|
||||
// { name: 'jane', email: 'jane@example.com', password: 'secret2' }
|
||||
// ]
|
||||
//
|
||||
// for (const user of users) {
|
||||
// const [hashedPassword, salt] = hashPassword(user.password)
|
||||
// await db.user.create({
|
||||
// data: {
|
||||
// name: user.name,
|
||||
// email: user.email,
|
||||
// hashedPassword,
|
||||
// salt
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
} catch (error) {
|
||||
console.warn('Please define your seed data.')
|
||||
console.error(error)
|
||||
}
|
||||
}
|
42
scripts/tsconfig.json
Normal file
42
scripts/tsconfig.json
Normal file
@ -0,0 +1,42 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"noEmit": true,
|
||||
"allowJs": true,
|
||||
"esModuleInterop": true,
|
||||
"target": "esnext",
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"baseUrl": "./",
|
||||
"paths": {
|
||||
"$api/*": [
|
||||
"../api/*"
|
||||
],
|
||||
"api/*": [
|
||||
"../api/*"
|
||||
],
|
||||
"$web/*": [
|
||||
"../web/*"
|
||||
],
|
||||
"web/*": [
|
||||
"../web/*"
|
||||
],
|
||||
"$web/src/*": [
|
||||
"../web/src/*",
|
||||
"../.redwood/types/mirror/web/src/*"
|
||||
],
|
||||
"web/src/*": [
|
||||
"../web/src/*",
|
||||
"../.redwood/types/mirror/web/src/*"
|
||||
],
|
||||
"types/*": ["../types/*", "../web/types/*", "../api/types/*"]
|
||||
},
|
||||
"typeRoots": ["../node_modules/@types"],
|
||||
"jsx": "preserve"
|
||||
},
|
||||
"include": [
|
||||
".",
|
||||
"../.redwood/types/includes/all-*",
|
||||
"../.redwood/types/includes/web-*",
|
||||
"../types"
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user