I wanna run my drizzle migrations (generate and push) before Next.js starts building my app so I can have access to the database and the tables at build time.
I'm experimenting with SelfHosting, I have my Postgres database and my Next app running in separate containers from a docker-compose, I managed to make my migrations be ready for when I visit my website on production, and it works nicely, I did this by having 3 services in my compose.yaml: 1- my database (db), 2- my database migrations (migrations, depends on db, and run the drizzle scripts), and 3- my Next.js app (web, that depens on db and migrations).
db => runs first
migrations => runs second (supposedly)
web => runs third
I do not understand why my Next.js app won't have access to my database tables if the migration service already executed at this point (supposedly, unless I'm wrong, please correct me).
The issue is that my Next.js pages that access the database need to be forced dynamic so it the build doesn't break when attemping to generate static pages, since migrations haven't been aplied (database is up and runnig tho, but it's empty because tables haven't been created)
Anyway, this is my first time working with Docker trying to deploy a full-stack app to my VPS, after trying so many different thing for the last week, I've come to the conclusion that this doesn't even make sense at all, why do I want to have my migrations ready at build time to genrate static pages if the static page output will be empty because the database will be empty anyway. And in the case I require to generate static pages that depend on data, this data would be pulled from an external database or external APIs or services and those exist out of my containers anyway, so my pages will still be able to pre-render.