technology.27.9.23
today’s a good day to document because I did a bunch of random shit – that worked.
the first thing that happened, I got the error I’ve been getting since last friday. the dreaded vercel migration error.
Error: P3009 migrate found failed migrations in the target database,
new migrations will not be applied. Read more about how to resolve
migration issues in a production database:
https://pris.ly/d/migrate-resolve
The`20230614002003_adds_organization` migration started at 2023-08-
10 18:49:16.744130 UTC failed Error: Command "npm run vercel-build"
exited with 1
the first thing I thought to do was to look in the logs
column of the _prisma_migration
table that prisma says should be there. it wasn’t locally, which made sense. well actually I can’t remember if I looked locally. What I really wanted was to look in my staging db, which I had never accessed from the CLI before.
However, on my way to beaming into my staging db, I came across two important updates: 1. that the found failed migrations in the db were from august and 2. this cal.com post that had gotten me unstuck in the past. legends.
these two tasks coalesced into a beautiful day of learning either a lot or absolutely nothing about db’s.
the cal.com post and the august date of the failed migration suggested to me that something I’d broken before was lodged between this migration attempt getting a proper go.
I did the rollback. and I switched by DATABASE_URL to my staging env, which in prisma is ‘preview’. but i couldn’t get it to work. me and my buddy gpt went in circles trying to figure out why the ef it wouldn’t. until, finally, way too late, I went to my old pal (sorry buddy) stack overflow. there, someone mentioned that people using next.js (and I assumed by extension trpc), would have trouble loading the DATABASE_URL string if their env file was anything other than .env
Mine was. Voila.
I changed the file. I made the rollback prisma migrate resolve --rolled-back "20230614002003_adds_organization"
but then… but then! thinking how to run this on my staging db stumped me. until finally I went back to the trusty docs and hit the prisma migrate deploy
60% confident it wouldn’t deploy the rollback to production. there was a hiccup or two. but I got a new migration error. and then, voila. it migrated.
I submitted a pr and in preview, everything was broken. despite the fact that my server code queried the new db. long story short. I had to accept the PR for vercel to use my server code. everything worked. everything now works. further (so long story short but a tiny bit longer), I had to npx prisma db push
. truly, i’m not sure what exactly this changed. I think once the server endpoints were being used in staging, and once the migration had finished, things were fine. but along with the PR, I did this. and one of them worked, though I think it was the PR. I think dp push sort of maybe wasn’t the move. I don’t think i’ve lost any data though.
OH yeah and I made two snapshots today! Wooohooo. A first. and second. of staging and of production.
integral to the success of the day was using
psql -h <hostname> -p <port> -U postgres -d <db name>
and then providing a password, which! is in the encrypted link you can copy from vercel.
from here, I got to mess around with the live staging data. which mean, I can do the same for production. which means, further, that I’m going to and that I have almost successfully completed this migration.