-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: upgrade prisma to 2.19.0 #130
Conversation
"db:migrate": "yarn -s prisma migrate up --experimental && yarn build:prisma", | ||
"db:rollback": "yarn prisma migrate down --experimental && yarn build:prisma", | ||
"db:migrate": "yarn -s prisma migrate deploy && yarn build:prisma", | ||
"db:rollback": "yarn prisma migrate reset && yarn build:prisma", |
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.
Is reset
correct here?
I think of reset
as a Full Reset, not a single rollback?
e.g.
db:reset
db:rollback
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.
That is great feedback! I think we should rename it. It does actually do a full reset and replays migrations. I need to dig back through but there wasn't a rollback per say, I think you literally need to reverse the SQL migration or do via a migration.
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.
@cmejet
Weird... that seems like an oversight on their part.
--
Actually just realized the new SQL migrations aren't in an up
/down
flow.
Maybe they add that in the next run... 🙏🏼
--
I would def rename this to reset
if that is the case.
We can figure out what a true rollback
looks like later. 👍🏼
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.
A good article I found as well about this specifically. I also like that they made a change that when you call reset it will run the seed file if it detects it there.
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.
After thinking about this more and chatting with Cory on Nest/CS work -- I get the reasoning... Still feels odd, but I get it.
-- CreateEnum | ||
CREATE TYPE "Role" AS ENUM ('ADMIN', 'USER'); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Profile" ( | ||
"id" TEXT NOT NULL, | ||
"userId" TEXT NOT NULL, | ||
"firstName" TEXT NOT NULL, | ||
"lastName" TEXT NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
||
PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "User" ( | ||
"id" TEXT NOT NULL, | ||
"email" TEXT NOT NULL, | ||
"password" TEXT NOT NULL, | ||
"roles" "Role"[], | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
||
PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Profile.userId_unique" ON "Profile"("userId"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "User.email_unique" ON "User"("email"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Profile" ADD FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
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.
* feat:upgrade chakra from RC to stable release * lock cross-fetch version * lock version of chakra
@@ -16,7 +16,7 @@ export async function createContext(context: ApolloApiContext): Promise<Context> | |||
let user: User | null = null; | |||
|
|||
if (authHeader) { | |||
user = await prisma.user.findOne({ where: { id: authHeader.userId } }); | |||
user = await prisma.user.findUnique({ where: { id: authHeader.userId } }); |
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.
This is a syntax change with the newest Prisma
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.
💯 had to do this recently in the CITJS repo as well
@@ -3,7 +3,7 @@ to: graphql/modules/<%= name %>.ts | |||
--- | |||
<% camelized = h.inflection.camelize(name) -%> | |||
<% plural = h.inflection.pluralize(camelized) -%> | |||
import { objectType, extendType } from '@nexus/schema'; | |||
import { objectType, extendType } from 'nexus'; |
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.
Library @nexus/schema
was deprecated and moved to nexus
@@ -178,6 +178,6 @@ export const SignupInput = inputObjectType({ | |||
definition: (t) => { | |||
t.string('email', { required: true }); | |||
t.string('password', { required: true }); | |||
t.field('profile', { type: 'ProfileCreateOneWithoutUserInput' }); | |||
t.field('profile', { type: 'ProfileCreateNestedOneWithoutUserInput' }); |
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.
Another syntax change with latest Prisma, discovered through build error and tracking down type generations
@@ -13,6 +13,7 @@ export const schema = makeSchema({ | |||
types, | |||
plugins: [ | |||
fieldAuthorizePlugin(), | |||
declarativeWrappingPlugin(), |
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.
This was required to add to the configuration in order to satisfy some of the current schema definitions we had.
https://nexusjs.org/docs/plugins/declarativeWrapping
alias: 'db', | ||
}, | ||
{ | ||
source: path.join(currentDirectory, 'graphql', 'context.ts'), | ||
module: path.join(currentDirectory, 'graphql', 'context.ts'), |
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.
This is the updated config Syntax, not documented well for the migration
@@ -6,14 +6,15 @@ | |||
"cacheDirectories": [".next/cache"], | |||
<% } -%> | |||
"scripts": { | |||
"build": "ts-node ./scripts/buildProd", | |||
"build": "node ./scripts/buildProd", |
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.
Updated to a js file due to build errors that started occurring. The script did not appear to need to be typescript as it was already using exports.module syntax and an empty export.
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.
I fixed this in the CITJS repo by overriding the module definition in the CLI params:
"ts-node": "ts-node --compiler-options '{\"module\":\"CommonJS\"}'",
Prisma has some notes on this:
https://www.prisma.io/docs/guides/application-lifecycle/seed-database#set-up-seeding-in-typescript
"db:rollback": "yarn prisma migrate down --experimental && yarn build:prisma", | ||
"db:migrate": "yarn -s prisma migrate dev && yarn build:prisma", | ||
"db:deploy": "yarn -s primsa deploy && yarn build:prisma", | ||
"db:reset": "yarn prisma migrate reset && yarn build:prisma", |
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.
Prisma no longer offers a direct rollback feature or migrate down
so we renamed the script to match the functionality which resets the database and then runs the seed file if found. This is intended to be used on dev only, not on production database.
"db:migrate": "yarn -s prisma migrate up --experimental && yarn build:prisma", | ||
"db:rollback": "yarn prisma migrate down --experimental && yarn build:prisma", | ||
"db:migrate": "yarn -s prisma migrate dev && yarn build:prisma", | ||
"db:deploy": "yarn -s primsa deploy && yarn build:prisma", |
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.
Prisma no longer uses the migrate up
command and instead favors deploy
@@ -22,7 +23,7 @@ | |||
"g:component": "hygen component new --name", | |||
"g:graphql": "hygen graphql new --name", | |||
"g:page": "hygen page new --name", | |||
"g:migration": "yarn -s prisma migrate save --experimental", | |||
"g:migration": "yarn -s prisma migrate dev", |
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.
Updated syntax for prisma 2.19.0
"start-server-and-test": "^1.11.2", | ||
"supertest": "^4.0.2", | ||
"ts-jest": "^26.1.3", | ||
"ts-node-dev": "^1.0.0", | ||
"typescript": "^3.9.7" | ||
"typescript": "^4.1.3" |
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.
Updated to match peer dependencies.
@@ -8,7 +8,7 @@ | |||
"forceConsistentCasingInFileNames": true, | |||
"noEmit": true, | |||
"esModuleInterop": true, | |||
"module": "esnext", | |||
"module": "commonjs", |
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.
All other tsconfig files are using commonjs and this started creating a build error when running buildProd, it was not happy with the empty export.
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.
See my comment above, you can still set this to esnext and override at the command level
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.
Small comments - only blocking change I see is trying the commonjs override so we can keep using ts-node for the build script.
@@ -16,7 +16,7 @@ export async function createContext(context: ApolloApiContext): Promise<Context> | |||
let user: User | null = null; | |||
|
|||
if (authHeader) { | |||
user = await prisma.user.findOne({ where: { id: authHeader.userId } }); | |||
user = await prisma.user.findUnique({ where: { id: authHeader.userId } }); |
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.
💯 had to do this recently in the CITJS repo as well
@@ -6,14 +6,15 @@ | |||
"cacheDirectories": [".next/cache"], | |||
<% } -%> | |||
"scripts": { | |||
"build": "ts-node ./scripts/buildProd", | |||
"build": "node ./scripts/buildProd", |
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.
I fixed this in the CITJS repo by overriding the module definition in the CLI params:
"ts-node": "ts-node --compiler-options '{\"module\":\"CommonJS\"}'",
Prisma has some notes on this:
https://www.prisma.io/docs/guides/application-lifecycle/seed-database#set-up-seeding-in-typescript
"@graphql-codegen/typescript-operations": "^1.17.6", | ||
"@graphql-codegen/typescript-react-apollo": "1.17.6", | ||
"@graphql-codegen/typescript-resolvers": "1.17.4", | ||
"@prisma/cli": "2.8.1", |
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.
👏
@@ -8,7 +8,7 @@ | |||
"forceConsistentCasingInFileNames": true, | |||
"noEmit": true, | |||
"esModuleInterop": true, | |||
"module": "esnext", | |||
"module": "commonjs", |
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.
See my comment above, you can still set this to esnext and override at the command level
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.
LGTM 👍
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.
LGTM
This PR upgrades Prisma to take advantage of the latest migrations and features available.
Changes
findUnique
instead offindOne
Screenshots
(prefer animated gif)
Checklist
Fixes #xxx