prisma / p1-to-p2-upgrade-path-feedback

4 stars 1 forks source link

Migrating Prisma 3 schema from Prisma 1 #14

Open LawJolla opened 2 years ago

LawJolla commented 2 years ago

Your Prisma 1 stack

What are you building with Prisma?

I am building ... multiple services, including GraphQL and REST, backed by a Prisma/Postgres instance.

Which version of Prisma 1 are you running?

I am running Prisma version ... 1.34

How do you access your Prisma server?

I am accessing my Prisma server with ... Prisma Client

Are you currently using nexus-prisma (with Prisma 1)?

How many Prisma services are you running on your production Prisma server?

2

Which database (incl. version) do you use?

I am using ... Postgres 10

Where is your Prisma server hosted?

My Prisma server is hosted on ... Fargate

Where is your database hosted?

My database is hosted on ... AWS

Where is your API server hosted?

My API server is hosted on ... Render

Your upgrade plans

What's your preferred upgrade strategy?

Do you want to use the new Nexus Framework when you upgrade?

Y

When do you want to upgrade?

Do you have any remaining questions or comments?

Thank you for everyone's hard work!

I need help syncing my schema.prisma with my migrated Prisma 1 db schema.

For background, I'm a solo developer with a massive Prisma 1 project. I've been working on this project since Prisma was GraphCool 2.0 so the amount of technical debt is enormous.

I spent at least 150 hours over the last several months migrating. I did the following..

Copied the Prisma 1 production schema for migration. Ran the prisma upgrade tool against my Prisma 1 datamodel. Made various SQL migrations manually. Changed Prisma Client 1 calls to Prisma Client 3. Upgraded Nexus (the bulk of my time)

What I'd like to do now it copy my current Prisma 1 schema, run the needed migrations, and cut the updated servers over to the new Prisma 3 client / migrated Prisma 1 schema.

The problem is I'm unable to sync my migration schema with schema.prisma.

Specifically, I can't even get an initial migration. I followed the directions here: https://www.prisma.io/docs/guides/database/developing-with-prisma-migrate/add-prisma-migrate-to-a-project#update-the-development-environment

I do not have any migration folder or files. However, I get the following output. Any help is very appreciated!

Drift detected: Your database schema is not in sync with your migration history.

The following is a summary of the differences between the expected database schema given your migrations files, and the actual schema of the database.

It should be understood as the set of changes to get from the expected schema to the actual schema.

If you are running this the first time on an existing database, please make sure to read this documentation page:
https://www.prisma.io/docs/guides/database/developing-with-prisma-migrate/troubleshooting-development

[+] Added enums
  - AccessControlEnum
  - AccountTypeEnum
  - AddressTypeEnum
  - ColorSchemeEnum
  - CustomVehicleSearchNotificationOptionsEnum
  - CustomerUIEnum
  - DealActionForEnum
  - DealActionTypeEnum
  - DealAddOnAddedByEnum
  - DealDeliveryType
  - DealLineItemTypeEnum
  - DealStatusEnum
  - DealTaskIsForEnum
  - DealTaskStatusEnum
  - DealTypeEnum
  - DealerUIEnum
  - DealershipIntegrationServiceAuthenticationTypeEnum
  - DealershipIntegrationTypeEnum
  - DocIsForEnum
  - DocTypeEnum
  - DrivelineEnum
  - EmailSubscriptionTypeEnum
  - EmailTypeEnum
  - EventEnum
  - FileTagEnum
  - FileTypeEnum
  - FloorPlanChargeTypeEnum
  - FuelEnum
  - LedgerTypeEnum
  - NotificationMethodEnum
  - OfferTypeEnum
  - OwnerEnum
  - PhoneNumberTypeEnum
  - RolesEnum
  - SideEffectsEnum
  - SignerTagEnum
  - StateEnum
  - TaxTypeEnum
  - TitleHistoryEnum
  - TransmissionEnum
  - UserViewEnum
  - VehicleBoughtFromEnum
  - VehicleDateTypeEnum
  - VehicleImageTagEnum
  - VehicleMileageEnum
  - VehicleOptionTagEnum
  - VehiclePriceTypeEnum
  - VehicleStatusEnum
  - VehicleTitleEnum
  - VehicleTypeEnum
  - VehicleVideoTypeEnum

[+] Added tables
  - AccountCheck
  - AccountTransaction
  - Address
  - _AddressToDeal
  - Advertising
  - AutomatedMessage
  - BridgeAccountTransactionToTransactionItem
  - CustomerPlaidAccount
  - CustomerVehicleSearch
  - Date
  - Deal
  - DealAction
  - DealAddOn
  - _DealAddOnLineItems
  - _DealAddOnToDoc
  - DealerAccount
  - DealerLicensePlate
  - DealerLicensePlateLog
  - DealerLicensePlateUser
  - Dealership
  - DealershipFloorPlan
  - DealershipIntegration
  - DealershipIntegrationService
  - DealLineItem
  - _DealSigner
  - _DealToEmailAddress
  - _DealToPhoneNumber
  - _DealToTrade
  - _DealToUser
  - _DealToVehicle
  - defaultArray
  - defaultString
  - Device
  - _DeviceToUser
  - Disclosure
  - _DisclosureToVehicle
  - Doc
  - _DocFile
  - _DocToSigner
  - _DocToUser
  - DriverLicense
  - ElectronicSignatureConsent
  - EmailAddress
  - EmailSubscriber
  - FacebookAd
  - FacebookAdGroup
  - File
  - FloorPlan
  - FloorPlanAction
  - FloorPlanLineItem
  - FloorPlanProvider
  - _FloorPlanToVehicle
  - InAppNotification
  - Note
  - Notification
  - Offer
  - Permission
  - PhoneNumber
  - _PhoneNumberToPhysicalAccess
  - PhysicalAccess
  - PhysicalAccessLog
  - PlaidAccount
  - SignedDoc
  - Signer
  - SignerTag
  - SiteBanner
  - Store
  - Task
  - Trade
  - TransactionItem
  - TransactionTypeAllowedList
  - User
  - UserNotificationPreference
  - _UserTask
  - Vehicle
  - VehicleBoughtFrom
  - VehicleDates
  - VehicleHistoryReport
  - VehicleImage
  - VehicleImageTag
  - VehicleOption
  - VehicleOptionTag
  - VehiclePrice
  - VehicleRecon
  - VehicleTaxPolicy
  - VehicleVideo
  - Vendor
  - WebUpdate

[*] Changed the `AccountCheck` table
  [+] Added foreign key on columns (account)

[*] Changed the `AccountTransaction` table
  [+] Added unique index on columns (check)
  [+] Added unique index on columns (uniqueTransactionId)
  [+] Added foreign key on columns (account)
  [+] Added foreign key on columns (check)
  [+] Added foreign key on columns (dealership)

[*] Changed the `Address` table
  [+] Added foreign key on columns (user)
  [+] Added foreign key on columns (vendor)

[*] Changed the `Advertising` table
  [+] Added unique index on columns (facebook)
  [+] Added foreign key on columns (facebook)
  [+] Added foreign key on columns (vehicleId)

[*] Changed the `AutomatedMessage` table
  [+] Added foreign key on columns (deal)

[*] Changed the `BridgeAccountTransactionToTransactionItem` table
  [+] Added foreign key on columns (dealership)
  [+] Added foreign key on columns (vendor)

[*] Changed the `CustomerPlaidAccount` table
  [+] Added foreign key on columns (user)

[*] Changed the `CustomerVehicleSearch` table
  [+] Added foreign key on columns (user)

[*] Changed the `Date` table
  [+] Added foreign key on columns (action)
  [+] Added foreign key on columns (deal)

[*] Changed the `Deal` table
  [+] Added foreign key on columns (dealership)
  [+] Added foreign key on columns (store)

[*] Changed the `DealAction` table
  [+] Added foreign key on columns (addOn)
  [+] Added foreign key on columns (deal)
  [+] Added foreign key on columns (dealership)
  [+] Added foreign key on columns (inheritsFrom)
  [+] Added foreign key on columns (store)
  [+] Added foreign key on columns (vehicle)

[*] Changed the `DealAddOn` table
  [+] Added foreign key on columns (deal)
  [+] Added foreign key on columns (dealership)
  [+] Added foreign key on columns (inheritsFrom)
  [+] Added foreign key on columns (inheritsFromId)
  [+] Added foreign key on columns (store)
  [+] Added foreign key on columns (vehicle)

[*] Changed the `DealLineItem` table
  [+] Added foreign key on columns (action)
  [+] Added foreign key on columns (deal)
  [+] Added foreign key on columns (dealAddOnId)
  [+] Added foreign key on columns (dealership)
  [+] Added foreign key on columns (inheritsFrom)
  [+] Added foreign key on columns (store)
  [+] Added foreign key on columns (task)
  [+] Added foreign key on columns (transaction)
  [+] Added foreign key on columns (vehicleFee)

[*] Changed the `DealerAccount` table
  [+] Added unique index on columns (plaid)
  [+] Added foreign key on columns (dealership)
  [+] Added foreign key on columns (plaid)

[*] Changed the `DealerLicensePlate` table
  [+] Added foreign key on columns (dealership)
  [+] Added foreign key on columns (store)

[*] Changed the `DealerLicensePlateLog` table
  [+] Added foreign key on columns (dealerLicensePlate)
  [+] Added foreign key on columns (dealerLicensePlateUser)
  [+] Added foreign key on columns (dealership)
  [+] Added foreign key on columns (plateUser)
  [+] Added foreign key on columns (store)
  [+] Added foreign key on columns (user)
  [+] Added foreign key on columns (vehicle)

[*] Changed the `DealerLicensePlateUser` table
  [+] Added foreign key on columns (address)
  [+] Added foreign key on columns (dealership)
  [+] Added foreign key on columns (driverLicense)
  [+] Added foreign key on columns (user)

[*] Changed the `Dealership` table
  [+] Added unique index on columns (email)
  [+] Added unique index on columns (host)
  [+] Added unique index on columns (name)
  [+] Added unique index on columns (slug)

[*] Changed the `DealershipFloorPlan` table
  [+] Added foreign key on columns (dealership)
  [+] Added foreign key on columns (floorPlanProvider)

[*] Changed the `DealershipIntegration` table
  [+] Added foreign key on columns (dealership)
  [+] Added foreign key on columns (service)

[*] Changed the `Device` table
  [+] Added unique index on columns (uuid)

[*] Changed the `Doc` table
  [+] Added foreign key on columns (completedFile)
  [+] Added foreign key on columns (deal)
  [+] Added foreign key on columns (dealership)
  [+] Added foreign key on columns (inheritsFrom)
  [+] Added foreign key on columns (store)
  [+] Added foreign key on columns (vehicle)

[*] Changed the `DriverLicense` table
  [+] Added foreign key on columns (address)
  [+] Added foreign key on columns (file)

[*] Changed the `EmailAddress` table
  [+] Added foreign key on columns (user)

[*] Changed the `EmailSubscriber` table
  [+] Added foreign key on columns (dealer)
  [+] Added foreign key on columns (user)

[*] Changed the `FacebookAd` table
  [+] Added foreign key on columns (advertisingId)

[*] Changed the `FacebookAdGroup` table
  [+] Added foreign key on columns (dealership)

[*] Changed the `File` table
  [+] Added unique index on columns (Key)
  [+] Added foreign key on columns (deal)
  [+] Added foreign key on columns (dealership)
  [+] Added foreign key on columns (signer)
  [+] Added foreign key on columns (store)
  [+] Added foreign key on columns (user)
  [+] Added foreign key on columns (vehicle)

[*] Changed the `FloorPlan` table
  [+] Added foreign key on columns (floorPlanProvider)

[*] Changed the `FloorPlanAction` table
  [+] Added foreign key on columns (floorplan)

[*] Changed the `FloorPlanLineItem` table
  [+] Added foreign key on columns (floorPlan)

[*] Changed the `InAppNotification` table
  [+] Added foreign key on columns (notification)
  [+] Added foreign key on columns (user)

[*] Changed the `Note` table
  [+] Added foreign key on columns (deal)
  [+] Added foreign key on columns (dealership)
  [+] Added foreign key on columns (from)
  [+] Added foreign key on columns (vehicle)

[*] Changed the `Offer` table
  [+] Added foreign key on columns (deal)

[*] Changed the `Permission` table
  [+] Added foreign key on columns (dealership)
  [+] Added foreign key on columns (user)

[*] Changed the `PhoneNumber` table
  [+] Added foreign key on columns (user)
  [+] Added foreign key on columns (vendor)

[*] Changed the `PhysicalAccess` table
  [+] Added foreign key on columns (user)

[*] Changed the `PhysicalAccessLog` table
  [+] Added foreign key on columns (access)

[*] Changed the `PlaidAccount` table
  [+] Added unique index on columns (accountId)
  [+] Added foreign key on columns (dealership)

[*] Changed the `SignedDoc` table
  [+] Added foreign key on columns (doc)
  [+] Added foreign key on columns (signer)

[*] Changed the `Signer` table
  [+] Added unique index on columns (electronicConsent)
  [+] Added foreign key on columns (electronicConsent)
  [+] Added foreign key on columns (user)

[*] Changed the `SignerTag` table
  [+] Added foreign key on columns (signer)

[*] Changed the `SiteBanner` table
  [+] Added foreign key on columns (dealership)

[*] Changed the `Store` table
  [+] Added unique index on columns (slug)
  [+] Added foreign key on columns (dealership)

[*] Changed the `Task` table
  [+] Added unique index on columns (uniqueId)
  [+] Added foreign key on columns (addOns)
  [+] Added foreign key on columns (deal)
  [+] Added foreign key on columns (dealership)
  [+] Added foreign key on columns (store)
  [+] Added foreign key on columns (vehicle)

[*] Changed the `TransactionItem` table
  [+] Added foreign key on columns (accountTransaction)
  [+] Added foreign key on columns (check)
  [+] Added foreign key on columns (dealership)
  [+] Added foreign key on columns (vendor)

[*] Changed the `TransactionTypeAllowedList` table
  [+] Added foreign key on columns (dealership)

[*] Changed the `User` table
  [+] Added foreign key on columns (dealership)
  [+] Added foreign key on columns (driverLicense)
  [+] Added foreign key on columns (worksFor)

[*] Changed the `UserNotificationPreference` table
  [+] Added foreign key on columns (user)

[*] Changed the `Vehicle` table
  [+] Added unique index on columns (advertising)
  [+] Added foreign key on columns (advertising)
  [+] Added foreign key on columns (dealership)
  [+] Added foreign key on columns (store)
  [+] Added foreign key on columns (vehicleBoughtFrom)

[*] Changed the `VehicleBoughtFrom` table
  [+] Added foreign key on columns (address)
  [+] Added foreign key on columns (vendor)

[*] Changed the `VehicleDates` table
  [+] Added foreign key on columns (vehicle)

[*] Changed the `VehicleImage` table
  [+] Added foreign key on columns (vehicle)

[*] Changed the `VehicleImageTag` table
  [+] Added foreign key on columns (image)

[*] Changed the `VehicleOption` table
  [+] Added foreign key on columns (vehicle)

[*] Changed the `VehicleOptionTag` table
  [+] Added foreign key on columns (vehicleOption)

[*] Changed the `VehiclePrice` table
  [+] Added foreign key on columns (user)
  [+] Added foreign key on columns (vehicle)

[*] Changed the `VehicleRecon` table
  [+] Added unique index on columns (bankLink)
  [+] Added foreign key on columns (bankLink)
  [+] Added foreign key on columns (vehicle)
  [+] Added foreign key on columns (vendor)

[*] Changed the `VehicleTaxPolicy` table
  [+] Added foreign key on columns (store)

[*] Changed the `VehicleVideo` table
  [+] Added foreign key on columns (vehicle)

[*] Changed the `Vendor` table
  [+] Added foreign key on columns (dealership)

[*] Changed the `WebUpdate` table
  [+] Added foreign key on columns (dealer)

[*] Changed the `_AddressToDeal` table
  [+] Added unique index on columns (A, B)
  [+] Added index on columns (B)
  [+] Added foreign key on columns (A)
  [+] Added foreign key on columns (B)

[*] Changed the `_DealAddOnLineItems` table
  [+] Added unique index on columns (A, B)
  [+] Added index on columns (B)
  [+] Added foreign key on columns (A)
  [+] Added foreign key on columns (B)

[*] Changed the `_DealAddOnToDoc` table
  [+] Added unique index on columns (A, B)
  [+] Added index on columns (B)
  [+] Added foreign key on columns (A)
  [+] Added foreign key on columns (B)

[*] Changed the `_DealSigner` table
  [+] Added unique index on columns (A, B)
  [+] Added index on columns (B)
  [+] Added foreign key on columns (A)
  [+] Added foreign key on columns (B)

[*] Changed the `_DealToEmailAddress` table
  [+] Added unique index on columns (A, B)
  [+] Added index on columns (B)
  [+] Added foreign key on columns (A)
  [+] Added foreign key on columns (B)

[*] Changed the `_DealToPhoneNumber` table
  [+] Added unique index on columns (A, B)
  [+] Added index on columns (B)
  [+] Added foreign key on columns (A)
  [+] Added foreign key on columns (B)

[*] Changed the `_DealToTrade` table
  [+] Added unique index on columns (A, B)
  [+] Added index on columns (B)
  [+] Added foreign key on columns (A)
  [+] Added foreign key on columns (B)

[*] Changed the `_DealToUser` table
  [+] Added unique index on columns (A, B)
  [+] Added index on columns (B)
  [+] Added foreign key on columns (A)
  [+] Added foreign key on columns (B)

[*] Changed the `_DealToVehicle` table
  [+] Added unique index on columns (A, B)
  [+] Added index on columns (B)
  [+] Added foreign key on columns (A)
  [+] Added foreign key on columns (B)

[*] Changed the `_DeviceToUser` table
  [+] Added unique index on columns (A, B)
  [+] Added index on columns (B)
  [+] Added foreign key on columns (A)
  [+] Added foreign key on columns (B)

[*] Changed the `_DisclosureToVehicle` table
  [+] Added unique index on columns (A, B)
  [+] Added index on columns (B)
  [+] Added foreign key on columns (A)
  [+] Added foreign key on columns (B)

[*] Changed the `_DocFile` table
  [+] Added unique index on columns (A, B)
  [+] Added index on columns (B)
  [+] Added foreign key on columns (A)
  [+] Added foreign key on columns (B)

[*] Changed the `_DocToSigner` table
  [+] Added unique index on columns (A, B)
  [+] Added index on columns (B)
  [+] Added foreign key on columns (A)
  [+] Added foreign key on columns (B)

[*] Changed the `_DocToUser` table
  [+] Added unique index on columns (A, B)
  [+] Added index on columns (B)
  [+] Added foreign key on columns (A)
  [+] Added foreign key on columns (B)

[*] Changed the `_FloorPlanToVehicle` table
  [+] Added unique index on columns (A, B)
  [+] Added index on columns (B)
  [+] Added foreign key on columns (A)
  [+] Added foreign key on columns (B)

[*] Changed the `_PhoneNumberToPhysicalAccess` table
  [+] Added unique index on columns (A, B)
  [+] Added index on columns (B)
  [+] Added foreign key on columns (A)
  [+] Added foreign key on columns (B)

[*] Changed the `_UserTask` table
  [+] Added unique index on columns (A, B)
  [+] Added index on columns (B)
  [+] Added foreign key on columns (A)
  [+] Added foreign key on columns (B)

? We need to reset the PostgreSQL database "prisma" at "prisma-[aws]".
Do you want to continue? All data will be lost. › (y/N)
Jolg42 commented 2 years ago

Hi @LawJolla, you are almost there I see! Let's get you to the final part 💯

So Prisma Migrate (v2 & v3) relies on a _prisma_migrations table to record which migrations were applied (with success or not). Since you are coming from Prisma 1 with an existing database, it doesn't exist When this table doesn't exist migrate dev will always ask for reset and is not safe to use against a production database.

You will need to baseline your production database, it will create that table and mark the baseline migration to be ignored.

I would recommend you to use pg_dump to create the baseline migration to get the perfect copy of your database schema.

Then try it out locally with prisma migrate dev (no need to baseline locally).

If your local env works, then you can go for base lining the production (or staging) database using prisma migrate resolve [....]

See more details in https://www.prisma.io/docs/guides/database/developing-with-prisma-migrate/baselining

Jolg42 commented 2 years ago

Bash example

# Create `migrations` directory and a `20220323155236_baseline` directory and move there
mkdir -p migrations/$(date +%Y%m%d%H%M%S)_baseline && cd "$_"

# Create a "dump" of the database schema in a `migration.sql` file 
pg_dump --file=migration.sql --schema-only --dbname=tests --host=localhost --username=prisma --password
LawJolla commented 2 years ago

Thanks @Jolg42 !

I've dumped by prod db to migrate. I've been coding against the dumped prod. Now I'm trying to baseline that dumped prod.

The part I'm not understanding is to get a baseline, it wants to reset the database. Is that normal? I just need to do it against a dump.. of the dump? :) And then see if it baselines the original migrate dump?

(I can't baseline the actual prod schema because of all of the 1 to 3 breaking changes. I'll need to take the site down, dump prod, and then try to apply all of the schema changes. I just want to make sure the prod database will be in a condition to migrate.)

janpio commented 2 years ago

Hey @LawJolla, sorry for not following up here sooner. I think read this, was confused a bit and then hoped someone else would follow up.

Could you please explain your steps again 1 by 1, starting with your Prisma 1 database? We really need to understand what exactly you are doing (which commands you run against which database etc) to be able to figure this out.

It should start something like this:

  1. I have a Prisma 1 project with a production database
  2. I ... and use command ... to ... and modify ... manually ...
  3. ...

Then I think we can understand better. Thanks! Let's get this over the finish line.

LawJolla commented 2 years ago

Thanks @janpio !

I'll do my best, but I've done the migration over many months didn't write down every command.

I have a huge project (5 servers, 2 front ends) that I've developed over the past 5 years where I'm the only developer. Migrating from Prisma 1 to 2 and Nexus migration required months of work to overcome the technical debt.

My end goal is to migrate my current production schema from Prisma 1 to 3 and merge my Prisma 3 branches into master. In other words, cut everything over to production data.

What's currently stopping that cut over is I'm unable to get my current migration schema to work with prisma migrate because of schema incompatibilities.

Let me try this from a high level overview.

  1. I have a Prisma 1 project with a production database. Prisma 1 server is on Fargate backed by Postgres RDS.
  2. I pg_dump ed my database and cloned my production schema and data
  3. I pg_restore ed my database so my migration schema and production schema are on the same db instance. (It's low traffic, so while using my production database as a migration test target isn't great practice, it works for my application)
  4. I made a prisma2 package for my monorepo
  5. I ran npx prisma-upgrade
  6. I spent the next several months:
  7. On my prisma-3 git branch, my migrated servers now work with Prisma 3 client, Nexus, the current schema.prisma file, and the migration database.
  8. But when I try to prisma migrate (sorry for using "migrate" everywhere 🤣) my migration schema, I get the errors described in the first post and am unsure how to make the schema.prisma compatible with the current migration schema on my Postgres instance.

Did that help at all? 😬

janpio commented 2 years ago

Of course it did.

A few questions: a) What do you refer to by "migration schema"? A copy of your database that you tried to adapt to be Prisma 2+ compatible? b) What does "4. I made a prisma2 package for my monorepo" mean exactly? c) What branch was the work of steps 4 to 5 made? ALso the prisma-3 one you mention later? d) Where are you trying prisma migrate on in step 8? What command exactly? e) How do you imagine the final "update" to work for you? Do you still have all the SQL changes you made to your database along the way manually, triggered by prisma-upgrade or other realizations? f) I assume the data in your production database changed a lot since you started this?

LawJolla commented 2 years ago

Thanks for the response!

Of course it did.

A few questions: a) What do you refer to by "migration schema"? A copy of your database that you tried to adapt to be Prisma 2+ compatible?

Yes. I'm trying to use the Postgres terminology correctly (database vs schema vs table) but I may be wrong. Here's a diagram that will hopefully help.

Image 2022-04-06 at 2 06 57 PM

b) What does "4. I made a prisma2 package for my monorepo" mean exactly?

That I don't know how to write clear sentences. 😬 🙈 I meant to say "I made a prisma2 branch for my monorepo." Sorry!

c) What branch was the work of steps 4 to 5 made? ALso the prisma-3 one you mention later?

Same branch. Sorry for the confusion. Midway through I changed the target from Prisma 2 to 3.

d) Where are you trying prisma migrate on in step 8? What command exactly?

▶ prisma migrate dev --name initial-migration --create-only

e) How do you imagine the final "update" to work for you? Do you still have all the SQL changes you made to your database along the way manually, triggered by prisma-upgrade or other realizations?

Yes, I saved the manual SQL commands as I went along. To the extent I'm missing any, I'm sure I can figure them out again. (I cut my teeth in the LAMP stack, so while I'm not a SQL expert, I'm not afraid of it either)

Once I know I can get my migration schema "cc$migration" to work with prisma migrate, I imagine the final update will involve me taking the site down on a weekend. I'll copy the "wk$prod" Prisma 1 schema as "cc$prod" and apply all of the prisma-upgrade and manual updates I just referenced above. Then I'll merge the prisma3 branch into production and hopefully the change will be complete.

f) I assume the data in your production database changed a lot since you started this? Yes. It's a car dealership with a full admin backend, an advertising server (generates Facebook and other ads), etc.

It's one of the bigger projects you'll see tacked by one developer.

Image 2022-04-06 at 3 27 17 PM

My Prisma 3 schema is 1772 lines.

And here's the types from just part of one of the servers... Image 2022-04-06 at 3 29 47 PM

All of that is to say I'm, at times, overwhelmed by this migration and greatly, greatly appreciate your and Prisma's support. I've been a part of the community since Graphcool and really went all in on Prisma 1.

And if you're curious, the front end is at:

https://www.buycrosscut.com

Thanks again!

janpio commented 2 years ago

What is the state of the _prisma_migrations tabel before you get to step 8? If it is empty or even missing, I think you really need to baseline and probably misunderstood above.

Let me try to explain again:

You are getting the Drift detected: Your database schema is not in sync with your migration history. message because your migration history table and folders are empty, but your database already has some tables. That is usually bad.

To avoid that, we have a thing called "baselining" which tells Migrate that this is all expected. You achieve that by a) creating a dump of the database structure into a .sql file, and b) putting that into a migration folder and telling Migrate that you "already applied it" with e.g. npx prisma migrate resolve --applied 20210426141759_initial-migration-for-db.

@Jolg42 had shared two commands above that should help with that: https://github.com/prisma/p1-to-p2-upgrade-path-feedback/issues/14#issuecomment-1076475030

When you have done that, the next run of migrate dev should not show this message any more but probably tell you that your database is up to date with your Prisma schema and there is nothing to do.