KeystoneJS Prisma Migration

migrating an existing PostGreSQL database with the KeystoneJS ORM takes a bit of doc reading. Essentially mashing the Command Line - Keystone 6 Docs and link articles together

while in the ./backend keystonejs root directory

mkdir -p migrations/0_init
npx prisma migrate diff \
--from-empty \
--to-schema-datamodel schema.prisma \
--script > migrations/0_init/migration.sql
npx prisma migrate resolve --applied 0_init

run below command to double check

yarn keystone build && keystone prisma migrate deploy

File tree for reference

.
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ README.md
β”œβ”€β”€ access.ts
β”œβ”€β”€ auth.ts
β”œβ”€β”€ crontab
β”‚Β Β  └── subscription_cron.ts
β”œβ”€β”€ keystone.ts
β”œβ”€β”€ migrations
β”‚Β Β  └── 0_initial
				migration.sql <---- ** here
β”œβ”€β”€ mutations
β”‚Β Β  β”œβ”€β”€ addToCart.ts
β”‚Β Β  β”œβ”€β”€ checkout.ts
β”‚Β Β  β”œβ”€β”€ contact.ts
β”‚Β Β  └── sampleMutation.ts
β”œβ”€β”€ package.json
β”œβ”€β”€ prepareToUpload.ts
β”œβ”€β”€ public
β”‚Β Β  β”œβ”€β”€ assets
β”‚Β Β  β”œβ”€β”€ seedfiles
β”‚Β Β  └── styles
β”œβ”€β”€ schema.graphql
β”œβ”€β”€ schema.prisma
β”œβ”€β”€ schema.ts
β”œβ”€β”€ schemas
β”œβ”€β”€ tsconfig.json
β”œβ”€β”€ types.ts
└── yarn.lock

Still not working

problem

Still having problems with this build. For now I connect my dev app environment with my production database and run yarn dev to update the schema, probably not a good idea but it's what works for now