Upgrade Prisma 1 to Prisma 2 with Apollo + GraphQL

Viewed 318

I have a problem upgrading from Prisma 1 to Prisma 2. The documentation is quite complicated for me. I currently have a small project using :

 "dependencies": {
    "bcryptjs": "2.4.3",
    "graphql-yoga": "1.18.3",
    "jsonwebtoken": "8.5.1",
    "prisma-binding": "1.5.19"
  },
  "devDependencies": {
    "dotenv": "5.0.1",
    "graphql-cli": "2.17.0",
    "nodemon": "1.19.4",
    "npm-run-all": "4.1.5",
    "prisma": "^1.34.10"
  }

My prisma.yml :

endpoint: ${env:PRISMA_ENDPOINT}

secret: ${env:PRISMA_SECRET}

datamodel: datamodel.graphql

hooks:
  post-deploy:
    - prisma generate

generate:
  - generator: graphql-schema
    output: ../src/generated/prisma.graphql

I used scripts :

  "scripts": {
    "start:dev": "nodemon -e js,graphql -x node -r dotenv/config src/index.js",
    "start": "node src/index.js",
    "debug": "nodemon -e js,graphql -x node --inspect -r dotenv/config src/index.js",
    "playground": "graphql playground",
    "dev": "npm-run-all --parallel start playground",
    "deploy": "prisma1 deploy --env-file .env"
  },

And this graphqlconfig

projects:
  app:
    schemaPath: "src/schema.graphql"
    extensions:
      endpoints:
        default: "http://localhost:4000"
  prisma:
    schemaPath: "src/generated/prisma.graphql"
    extensions:
      prisma: database/prisma.yml

How can I update prisma? Knowing that my frontend is based on VueJS with ApolloClient, graphlq, graphql-tag

Thanks a lot to you, the backend part is not something simple for me

And here is my tree structure

E D I T

Thanks for your anwser. Nice, @nburk

But I have a problem on the 3rd step : https://www.prisma.io/docs/guides/upgrade-guides/upgrade-from-prisma-1/upgrading-the-prisma-layer-postgres

(Connection URL)

Previously I don't used "docker-compose". I deployed my front + back + DB on Heroku with Prisma

const { Prisma } = require("prisma-binding");
const resolvers = require("./resolvers");

// GraphQL Yoga Server
const server = new GraphQLServer({
  typeDefs: "src/schema.graphql",
  resolvers,
  context: (req) => ({
    ...req,
    db: new Prisma({
      typeDefs: "src/generated/prisma.graphql", // DB Prisma Schema
      endpoint: process.env.PRISMA_ENDPOINT, // Prisma Service
      secret: process.env.PRISMA_SECRET, // Prisma Secret
      debug: true,
    }),
  }),
});


server.start(() =>
  console.log(`Server is running on ${process.env.PRISMA_ENDPOINT}`)
);

With a DB hosted on Heroku (.env file)

PRISMA_ENDPOINT="https://lprojet-name-db.herokuapp.com/database/prod"

And when I used npx prisma introspect I have this error

Introspecting based on datasource defined in prisma/schema.prisma …
Error: P1001

Can't reach database server at `'localhosh':'5432'

Please make sure your database server is running at 'localhost':'5432' I think the problem comes from the schema.prisma which requires to have a url starting with postgresql:// but with Prisma1 I didn't need to go through that.

How can I transform my old DB URL (currently hosted on Heroku)?

Thanks

EDIT 2

I used

DATABASE_URL=postgres://..........eu-west-1.compute.amazonaws.com:5432/d9ptc61fera9g1

And I have a "database empty" error, but my database isn't empty. This UR come from Heroku Database Config

1 Answers

Nikolas from Prisma here!

We have written extensive upgrade documentation that walks you through the upgrade process. Here's some guides you can follow:

  1. How to upgrade: Provides a general overview and explains different upgrade strategies
  2. Upgrading the Prisma layer: Explains how to adjust your database schema using the Prisma Upgrade CLI
  3. prisma-binding to SDL-first: Explains how to upgrade your GraphQL schema and resolvers

Feel free to follow up in case you have any questions along the way, always happy to help :)

Related