Hello! Thanks for you hard work, all the contribut...
# orm-help
d
Hello! Thanks for you hard work, all the contributors! I'm new to Prisma and got into an existing project for devops task. What I'm looking for is a way to migrate from prisma 1 cloud, which will be deprecated very soon, to self-hosted prisma v3 infrastructure. Code base has been already migrated to use Prisma v3 APIs, so this is specifically for hosting the prisma infrastructure. Assuming that we've already hosted our new MySQL database on the AWS RDS, what steps should I follow? And, Is this docker image legit for production deployment?
prismagraphql/prisma
1
a
Hi, and welcome to the Prisma Community 👋🏾
Assuming that we’ve already hosted our new MySQL database on the AWS RDS, what steps should I follow?
The next step would be defining the
DATABASE_URL
environment variable for your project in your deployment provider for your API. If you’re using a relational database in production, you will need to sync your API’s Prisma schema with the database schema before deploying the application using Prisma Migrate with
npx prisma migrate deploy
if you have a migration history.
prisma migrate deploy
applies any pending migrations to your database. You can then generate Prisma Client in the deployment step – which will be used by your APIs – using
npx prisma generate
. I would recommend taking a look at our Getting Started guide to familiarize yourself with Prisma.
And, Is this docker image legit for production deployment?
prismagraphql/prisma
I’ll reach out to our product/ engineering team and I’ll let you know. Let me know if you have any further questions. 🙂
d
Thank you so so much!
The next step would be defining the
DATABASE_URL
environment variable for your project in your deployment provider for your API.
Could you elaborate this part? I didn't fully get it.
a
Prisma reads environment variables from the system’s environment. When you install Prisma for the first time it creates a convenience
.env
file for you to set your database’s connection string as an environment variable. When you use Prisma CLI or Prisma Client, the
.env
file content and the variables defined in there are put into the system’s environment, where Prisma can read it and use it. When deploying your application, you will need to define the environment variables in your deployment platform (eg Vercel), which Prisma will use for applying pending migrations and connecting + querying your database. Docs: Environment Variables
d
Gosh
Thanks again, it's that simple?
In the existing project, it uses this docker compose file for launching dev db and prisma interface:
Copy code
version: '3'
services:
  prisma:
    image: prismagraphql/prisma:1.34
    restart: always
    ports:
      - '4466:4466'
    environment:
      PRISMA_CONFIG: |
        port: 4466
        managementApiSecret: abcdef
        databases:
          default:
            connector: mysql
            host: mysql
            port: 3306
            user: root
            password: abcdef
            rawAccess: true
  mysql:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: abcdef
    volumes:
      - mysql:/var/lib/mysql
volumes:
  mysql: ~
And the dot env file looks like this:
Copy code
...
PRISMA_SECRET="prismasecret"
...
DB_ENDPOINT="<http://localhost:4466>"
...
PRISMA_MANAGEMENT_API_SECRET="ah791lejgh"
...
PRISMA_CLOUDSESSION_KEY=""
...
# This text is inserted by `prisma init`:
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: <https://pris.ly/d/prisma-schema#using-environment-variables>
# Prisma supports the native connection string format for PostgreSQL, MySQL and SQLite.
# See the documentation for all the connection string options: <https://pris.ly/d/connection-strings>
DATABASE_URL="<mysql://root:ah791lejgh@localhost:3306/default@default>"JWT_SECRET="secret"
...
My curiosity goes for the difference between
DB_ENDPOINT
and
DATABASE_URL
Sorry I wish I could share the entire code base, but it's proprietary
I can see this part in
PROJECT_ROOT/src/generated/prisma-client/index.js
:
And I can find this part as well(it's not a generated code):
That's all I think it's related to my upgrade
In the package.json file:
Copy code
"prisma-client-lib": "^1.34.12",
        "prisma1": "^1.34.12",
a
I think
DB_ENDPOINT
is being used by Prisma 1 and
DATABASE_URL
is being used by the latest version of Prisma (~2) 🤔
d
ahhhhh
a
Prisma Migrate and Prisma Client will pick up
DATABASE_URL
and use it for running database migrations and querying your database respectively.
d
So it sounds like I need to "generate" the prisma client again using the new version
prisma@3
(it's not prisma@4 because we are on node 12) right?
a
That’s correct!
fast parrot 1
d
Upgrade started, I will let you know once I'd be successful 💪
🚀 1
Having a trouble when importing the exported db data
Existing db data is kinda huge, and I successfully exported by
prisma1 export
coming back to the local env, and trying to import it, but seeing this error:
Copy code
Unzipping 10561ms
Uncaught exception, cleaning up: Error: Object {...,"onboarding":"plan",...} has the following unknown properties: onboarding
Validating data ✖
Do you have any idea?
It would be really great if I can directly connect to the underlying mysql db connected to the prisma1 cloud service. Is it possible?
Then I will be able to dump the sql and import it without any trouble
Everything works fine now EXCEPT for the data migration. Our production data is kinda huge and it's a really headache to migrate it to the new db from the legacy prisma1 cloud
n
Hey there 👋 did you manage to migrate the data in the end? Do I understand correctly that you currently have two different setups: • previous Prisma 1 stack: that’s still your production app running on Prisma 1 Cloud • new Prisma ORM stack: the code is ready but the DB is empty because you haven’t migrated the data yet And the last thing before you can switch your frontends to the new Prisma ORM stack is to migrate the data from the previous Prisma 1 stack?
d
Exactly!!
I'm stuck in there
n
For my understanding: The two DBs don’t have exactly the same SQL schema, right? Since the new Prisma ORM requires the data to be structured differently at times?
d
Yeeees
n
prisma export
from the Prisma 1 CLI is not very stable, it’s probably not the right tool to migrate the data…
d
But you know, there seems to be no way to create a plain sql dump off the prisma1 cloud by myself
One sec let me check
ah ye
n
But you know, there seems to be no way to create a plain sql dump off the prisma1 cloud by myself
Where is your DB hosted? You should be able to connect to it directly to export the data…
d
n
Or do you not have access to the DB? Afaik Prisma 1 Cloud only hosts the Prisma 1 server, but not actually your DB 🤔
in your Docker Compose file, this should be the part where you’re configuring the DB connection:
Copy code
databases:
          default:
            connector: mysql
            host: mysql
            port: 3306
            user: root
            password: abcdef
            rawAccess: true
d
I'm not the person who set it up initially, don't know where to find the db Last two rows are the dbs in use I guess
where can I find the docker compose file?
for prod and staging in use in prisma1
prisma1 cloud**
Afaik Prisma 1 Cloud only hosts the Prisma 1 server, but not actually your DB
It sounds like prisma1 is just like current version of prisma studio regarding what it was doing
So I need to find out the actual server where the docker compose file is deployed (mysql image + prisma1 image)
Right?
n
I think so! I’m also checking with my colleagues about this, we’re going to figure this out 😄
d
Yeeeees. I will also check with my colleagues if anybody knows where the actual db is. It's quite long lived project and currently live with many users, so several maintainers already replaced. Confusion came from there
Thank you so much for your sincere support!
n
I will also check with my colleagues if anybody knows where the actual db is.
Yeah, this would definitely be able! You’re not using a Demo server, right? You pretty much need to find that Docker Compose file that was used to spin everything up.
d
Found out the prisma1 deployment in AWS Fargate and 💥
Thank you very much for your help. It was really helpful!
@nikolasburk @Alex Ruheni Huge thanks to you guys!
I'm done with the full upgrade & migration
💯 1