PageSourceSearch

https://zenstack.dev/assets/js/46e8b731.225c862f.js

js zenstack.dev collected 2026-09-28 11:15:58 UTC 5,914 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkzenstack_docs=self.webpackChunkzenstack_docs||[]).push([[9596],{66204:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>a,default:()=>p,frontMatter:()=>r,metadata:()=>o,toc:()=>l});var t=n(2488),i=n(16592);const r={description:"Steps for migrating from existing Prisma projects.",sidebar_position:2},a="Migrating Existing Prisma Projects",o={id:"guides/existing-prisma",title:"Migrating Existing Prisma Projects",description:"Steps for migrating from existing Prisma projects.",source:"@site/versioned_docs/version-2.x/guides/existing-prisma.md",sourceDirName:"guides",slug:"/guides/existing-prisma",permalink:"/docs/2.x/guides/existing-prisma",draft:!1,unlisted:!1,editUrl:"https://github.com/zenstackhq/zenstack-docs/edit/main/versioned_docs/version-2.x/guides/existing-prisma.md",tags:[],version:"2.x",sidebarPosition:2,frontMatter:{description:"Steps for migrating from existing Prisma projects.",sidebar_position:2},sidebar:"mySidebar",previous:{title:"Development Workflow",permalink:"/docs/2.x/guides/dev-workflow"},next:{title:"Installing IDE Extensions",permalink:"/docs/2.x/guides/ide"}},c={},l=[{value:"Prisma generators' triple slash hack",id:"prisma-generators-triple-slash-hack",level:2}];function d(e){const s={a:"a",code:"code",h1:"h1",h2:"h2",li:"li",ol:"ol",p:"p",pre:"pre",...(0,i.M)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(s.h1,{id:"migrating-existing-prisma-projects",children:"Migrating Existing Prisma Projects"}),"\n",(0,t.jsxs)(s.p,{children:["ZenStack CLI provides an ",(0,t.jsx)(s.code,{children:"init"})," command for easily converting an existing Prisma project."]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-bash",children:"npx zenstack@latest init\n"})}),"\n",(0,t.jsx)(s.p,{children:"The command does the following things:"}),"\n",(0,t.jsxs)(s.ol,{children:["\n",(0,t.jsxs)(s.li,{children:["\n",(0,t.jsxs)(s.p,{children:["It copies over ",(0,t.jsx)(s.code,{children:"prisma/schema.prisma"})," to ",(0,t.jsx)(s.code,{children:"/schema.zmodel"}),"."]}),"\n",(0,t.jsxs)(s.p,{children:["If your Prisma schema is in a non-standard location, you can pass it in with the ",(0,t.jsx)(s.code,{children:"--prisma"})," option."]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-bash",children:"npx zenstack@latest init --prisma prisma/my.schema\n"})}),"\n"]}),"\n",(0,t.jsxs)(s.li,{children:["\n",(0,t.jsx)(s.p,{children:"It installs NPM packages."}),"\n",(0,t.jsxs)(s.p,{children:[(0,t.jsx)(s.code,{children:"zenstack"})," package as a dev dependency and ",(0,t.jsx)(s.code,{children:"@zenstackhq/runtime"})," as a regular dependency. The CLI tries to guess the package manager you use, but you can also explicitly specify one with the ",(0,t.jsx)(s.code,{children:"--package-manager"})," option (supported values are ",(0,t.jsx)(s.code,{children:"npm | pnpm | yarn"}),")."]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-bash",children:"npx zenstack@latest init --package-manager pnpm\n"})}),"\n"]}),"\n"]}),"\n",(0,t.jsxs)(s.p,{children:["If the ",(0,t.jsx)(s.code,{children:"init"})," command doesn't suit your needs, manually doing these steps is just fine. See ",(0,t.jsx)(s.a,{href:"../reference/cli",children:"ZenStack CLI"})," for more details about using the CLI."]}),"\n",(0,t.jsx)(s.h2,{id:"prisma-generators-triple-slash-hack",children:"Prisma generators' triple slash hack"}),"\n",(0,t.jsx)(s.p,{children:"One major limitation of Prisma schema is the lack of support for custom attributes and functions. Generators can't directly attach specific metadata to models. The community has been using the triple-slash comment hack as a workaround."}),"\n",(0,t.jsxs)(s.p,{children:["Here's an example from ",(0,t.jsx)(s.a,{href:"https://prisma.typegraphql.com/",children:"TypeGraphQL Prisma"}),'. The comment on the "password" field marks it to be omitted from both the GraphQL input and output types. The generator parses its text and acts accordingly.']}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-zmodel",metastring:"title='schema.prisma'",children:"model User {\n  id Int @default(autoincrement()) @id\n  email String  @unique\n  /// @TypeGraphQL.omit(output: true, input: true)\n  password String\n  posts Post[]\n}\n"})}),"\n",(0,t.jsx)(s.p,{children:"To make this scenario continue working, ZenStack preserves all triple-slash comments when generating the Prisma schema."}),"\n",(0,t.jsx)(s.p,{children:"The hack works but is error-prone because comments have no protection from the compiler. Fortunately, with ZModel, you can implement it in a much nicer way, thanks to its custom attributes support:"}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-zmodel",metastring:"title='schema.zmodel'",children:"\nattribute @TypeGraphQL.omit(output: Boolean?, input: Boolean?)\n\nmodel User {\n  id Int @default(autoincrement()) @id\n  email String  @unique\n  password String @TypeGraphQL.omit(output: true, input: true)\n  posts Post[]\n}\n"})}),"\n",(0,t.jsx)(s.p,{children:"Now, if you make a typo or pass in wrongly-typed expressions to the attribute, the compiler cat
1ches it for you. When ZenStack generates the Prisma schema, it translates all custom attributes back to triple-slash comments, so the original Prisma generators can continue working as before."})]})}function p(e={}){const{wrapper:s}={...(0,i.M)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.jsx)(d,{...e})}):d(e)}},16592:(e,s,n)=>{n.d(s,{I:()=>o,M:()=>a});var t=n(96651);const i={},r=t.createContext(i);function a(e){const s=t.useContext(r);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function o(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),t.createElement(r.Provider,{value:s},e.children)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.