-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Prisma's programmatic API for keystone-next generate (#5155)
- Loading branch information
Showing
13 changed files
with
216 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
'@keystone-next/keystone': minor | ||
'@keystone-next/adapter-prisma-legacy': minor | ||
--- | ||
|
||
Changed `keystone-next generate` so that it uses Prisma's programmatic APIs to generate migrations and it accepts the following options as command line arguments or as prompts: | ||
|
||
- `--name` to set the name of the migration | ||
- `--accept-data-loss` to allow resetting the database when it is out of sync with the migrations | ||
- `--allow-empty` to create an empty migration when there are no changes to the schema |
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,7 @@ | ||
--- | ||
'@keystone-next/keystone': major | ||
'@keystone-next/types': major | ||
'@keystone-next/adapter-prisma-legacy': major | ||
--- | ||
|
||
Removed `createOnly` migration mode |
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 |
---|---|---|
@@ -1,25 +1,26 @@ | ||
import path from 'path'; | ||
import { | ||
CLIOptionsForCreateMigration, | ||
createMigration, | ||
} from '@keystone-next/adapter-prisma-legacy'; | ||
import { createSystem } from '../../lib/createSystem'; | ||
import { initConfig } from '../../lib/initConfig'; | ||
import { requireSource } from '../../lib/requireSource'; | ||
import { saveSchemaAndTypes } from '../../lib/saveSchemaAndTypes'; | ||
import { CONFIG_PATH } from '../utils'; | ||
import type { StaticPaths } from '..'; | ||
|
||
export const generate = async ({ dotKeystonePath }: StaticPaths) => { | ||
console.log('🤞 Migrating Keystone'); | ||
|
||
export const generate = async ( | ||
{ dotKeystonePath }: StaticPaths, | ||
args: CLIOptionsForCreateMigration | ||
) => { | ||
const config = initConfig(requireSource(CONFIG_PATH).default); | ||
const { keystone, graphQLSchema, createContext } = createSystem( | ||
config, | ||
dotKeystonePath, | ||
'createOnly' | ||
); | ||
|
||
console.log('✨ Generating graphQL schema'); | ||
await saveSchemaAndTypes(graphQLSchema, keystone, dotKeystonePath); | ||
const { keystone } = createSystem(config, dotKeystonePath, 'none'); | ||
|
||
console.log('✨ Generating migration'); | ||
await keystone.connect({ context: createContext().sudo() }); | ||
|
||
await keystone.disconnect(); | ||
await keystone.adapter._generateClient(keystone._consolidateRelationships()); | ||
await createMigration( | ||
config.db.url, | ||
keystone.adapter.prismaSchema, | ||
path.resolve(keystone.adapter.schemaPath), | ||
args | ||
); | ||
}; |
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,6 @@ | ||
// preconstruct(kinda rightfully) gets annoying if you have an import from a ts file | ||
// to a non-ts file in the same package with no declarations so we need this | ||
|
||
export const PrismaAdapter: any; | ||
export const PrismaListAdapter: any; | ||
export const PrismaFieldAdapter: any; |
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 was deleted.
Oops, something went wrong.
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,3 @@ | ||
export { PrismaAdapter, PrismaListAdapter, PrismaFieldAdapter } from './adapter-prisma'; | ||
export { createMigration } from './migrations'; | ||
export type { CLIOptionsForCreateMigration } from './migrations'; |
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 |
---|---|---|
|
@@ -12843,13 +12843,6 @@ prism-react-renderer@^1.2.0: | |
resolved "https://registry.yarnpkg.com/prism-react-renderer/-/prism-react-renderer-1.2.0.tgz#5ad4f90c3e447069426c8a53a0eafde60909cdf4" | ||
integrity sha512-GHqzxLYImx1iKN1jJURcuRoA/0ygCcNhfGw1IT8nPIMzarmKQ3Nc+JcG0gi8JXQzuh0C5ShE4npMIoqNin40hg== | ||
|
||
[email protected]: | ||
version "2.18.0" | ||
resolved "https://registry.yarnpkg.com/prisma/-/prisma-2.18.0.tgz#b19a2d4a487b8b62759777be55506567af41f6ae" | ||
integrity sha512-03po/kFW3/oGHtnANgZiKYz22KEx6NpdaIP2r4eievmVam9f2+0PdP4x/KSFdMCT6B6VHh+3ILTi2z3bYosCgA== | ||
dependencies: | ||
"@prisma/engines" "2.18.0-34.da6fafb57b24e0b61ca20960c64e2d41f9e8cff1" | ||
|
||
process-nextick-args@~2.0.0: | ||
version "2.0.1" | ||
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2" | ||
|
215aed3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: