0.0.44 • Published 2 years ago

prisma-upgrade v0.0.44

Weekly downloads
44
License
ISC
Repository
github
Last release
2 years ago

Prisma Upgrade

Prisma Upgrade is a CLI tool to help Prisma 1 users using MySQL or Postgres to upgrade to Prisma 2+.

Scope

We spent a lot of time on this tool and are happy with the results. It's well-tested and working as intended. It's not perfect though, so you may need to make some manual adjustments after upgrading to clean up your final Prisma 2+ schema. See this issue for more details.

We recommend you download the Prisma VS Code extension to help with your transition.

Note: You should always run the SQL generated by this tool on your test or staging databases before running it on production.

Usage

$ npx prisma-upgrade

See our documentation for more information about how to upgrade your Prisma 1 datamodel to Prisma 2+.

Features

This table reflects the current feature set of the upgrade CLI and will be updated continuously. Read below for a more detailed explanation of each column.

ProblemMySQLPostgreSQLPrisma schemaPrisma 1 compatible
Database schema incompatibilities²
Default values aren't represented in database YesYesYesYes
Mismatching CUID length YesYesYesYes
@createdAt isn't represented in databaseYesYesYesYes
Inline 1-1 relations are recognized as 1-n (missing UNIQUE constraint) YesYesYesYes
Json type is represented as TEXT YesYesYesYes
Enum types are represented as TEXT in database YesYesYesYes
All non-inline relations are recognized as m-n Not yetNot yetNot yetNo
Scalar lists (arrays) are maintained with extra table Not yetNot yetNot yetNo
Prisma 2+ schema differences³
@updatedAt isn't represented in database n/an/aYesYes
Generated CUIDs as ID values aren't represented in database n/an/aYesYes
Maintain required 1-1-relationsn/an/aYesYes
Maintain order of models and fieldsn/an/aNot yetYes
Maintain relation namesn/an/aNot yetYes
@map and @@mapn/an/aYesYes
Cascading deletesNoNoNoNo

² = fixed by executing SQL statements
³ = fixed by making changes to Prisma 2+ schema

What do the columns mean?

  • MySQL: Does the CLI generate the correct MySQL statements to solve the problem?
  • PostgreSQL: Does the CLI generate correct PostgreSQL statements to solve the problem?
  • Prisma schema: Does the final Prisma 2+ schema I get from the CLI reflect the right solution?
  • Prisma 1 compatible: Does the SQL change to the schema maintain Prisma 1 compatibility?

How Prisma Upgrade (Technically) Works

We parse your Prisma 1 datamodel and your Prisma 2+ schema and run both ASTs through a set of rules. These rules produce operations. The operations are printed into SQL commands for you to run on your database.

Prisma upgrade is idempotent, so you can run it as many times as you want and it will produce the same result each time. Prisma upgrade only shows you commands you still need to run, it does not show you commands you've already run.

You'll also notice that we never connect to your database, we simply look at your Prisma 1 files and your Prisma 2+ schema and generate from there!

Development

To add a new test, follow the following steps:

  1. Create a new folder with one of the following prefixes: postgres-, mysql-, postgres1- or mysql1-. Use postgres- and mysql- for Prisma Prisma 1.34, postgres1 and mysql1- for versions before that.
  2. Add a prisma.yml and datamodel.graphql
  3. Run node scripts/sqldump.js. This should product a dump.sql file and a schema.prisma.
  4. Add an expected.sql. This is the commands you expect to prisma-upgrade to guide you to do. Often, I first leave this blank, see what prisma-upgrade does and then tweak.
  5. Add an expected.prisma. This is the final state the schema should be in. Often, I first leave this blank, see what prisma-upgrade does and then tweak.

Tests

Testing during implementation of this tool consists of 2 parts: a Local SQL Dump and Running Tests

Local SQL Dump

Requirements: MySQL@5, Docker

Since it's cumbersome to run Prisma 1 in CI, we need to locally setup test cases first

Setting up MySQL for examples

mysqladmin -h localhost -u root create prisma
mysql -h localhost -u root prisma < ./examples/mysql-ablog/dump.sql
mysqladmin -h localhost -u root drop prisma -f

Security

If you have a security issue to report, please contact us at security@prisma.io

0.0.44

2 years ago

0.0.43

3 years ago

0.0.42

4 years ago

0.0.41

4 years ago

0.0.40

4 years ago

0.0.39

4 years ago

0.0.38

4 years ago

0.0.37

4 years ago

0.0.36

4 years ago

0.0.35

4 years ago

0.0.34

4 years ago

0.0.33

4 years ago

0.0.32

4 years ago

0.0.31

4 years ago

0.0.30

4 years ago

0.0.29

4 years ago

0.0.28

4 years ago

0.0.27

4 years ago

0.0.25

4 years ago

0.0.26

4 years ago

0.0.24

4 years ago

0.0.23

4 years ago

0.0.22

4 years ago

0.0.21

4 years ago

0.0.20

4 years ago

0.0.18

4 years ago

0.0.19

4 years ago

0.0.17

4 years ago

0.0.16

4 years ago

0.0.13

4 years ago

0.0.14

4 years ago

0.0.15

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago

0.0.0

4 years ago