MCPcopy
hub / github.com/prisma/prisma / defaultSchema

Function defaultSchema

packages/cli/src/Init.ts:45–112  ·  view source on GitHub ↗
(props?: {
  datasourceProvider?: ConnectorType
  generatorProvider?: string
  previewFeatures?: string[]
  output?: string
  withModel?: boolean
})

Source from the content-addressed store, hash-verified

43 !!globalThis.Bun || !!globalThis.process?.versions?.bun
44
45export const defaultSchema = (props?: {
46 datasourceProvider?: ConnectorType
47 generatorProvider?: string
48 previewFeatures?: string[]
49 output?: string
50 withModel?: boolean
51}) => {
52 const {
53 datasourceProvider = 'postgresql',
54 generatorProvider = defaultGeneratorProvider,
55 previewFeatures = defaultPreviewFeatures,
56 output = '../generated/prisma',
57 withModel = false,
58 } = props ?? {}
59
60 let schema = `// This is your Prisma schema file,
61// learn more about it in the docs: https://pris.ly/d/prisma-schema
62
63// Get a free hosted Postgres database in seconds: \`npx create-db\`
64
65generator client {
66 provider = "${generatorProvider}"
67${
68 previewFeatures.length > 0
69 ? ` previewFeatures = [${previewFeatures.map((feature) => `"${feature}"`).join(', ')}]\n`
70 : ''
71} output = "${output}"
72}
73
74datasource db {
75 provider = "${datasourceProvider}"
76}
77`
78
79 // We add a model to the schema file if the user passed the --with-model flag
80 if (withModel) {
81 const defaultAttributes = `email String @unique
82 name String?`
83
84 switch (datasourceProvider) {
85 case 'mongodb':
86 schema += `
87model User {
88 id String @id @default(auto()) @map("_id") @db.ObjectId
89 ${defaultAttributes}
90}
91`
92 break
93 case 'cockroachdb':
94 schema += `
95model User {
96 id BigInt @id @default(sequence())
97 ${defaultAttributes}
98}
99`
100 break
101 default:
102 schema += `

Callers 2

Init.vitest.tsFile · 0.90
parseMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected