Closed humphd closed 1 year ago
@humphd I agree with the above, for multiple reasons
I have seen with my own eyes prisma db push
mess up (did not lose data, but did not become 100% consistent with the schema either) In these cases, even if Prisma messes up the migration script it can be manually corrected (but that individual has to be quite good in mysql)
This adds a second chance for the reviewer(s) to catch any major mistakes reading through the migration file
I think we should only establish the baseline once this becomes delpoyed to prod
We should mandate for someone to do testing on staging !!with pre-existing data!! before a migration can be deployed to prod: CI and local testing will bring up the db from scratch, but we'd still need to test the migrations too that is only possible on staging, (or on a copy of a deployed database)
TL;DR I agree, but I'd put it off as long as possible
P.S. Could we do a full export (db dump) of the prod database before a migration is run, and keep it in a secure storage for like 1 month?
@dadolhay maybe we should avoid automating the migrations with Prisma, and if we need to do one, we have to do it manually? Then we can bring down the instances, run a backup, migrations, test manually, etc. We'll still have a problem, though. In staging, our idea was to deploy when we land on main
. If we ever land a schema change on main
, it will cause issues. So we'd have to somehow come-up with a work around for this. With production, we can do it when we tag, so it requires manually opt-in. It's still a bit complicated. Thoughts?
I agree with leaving the baseline as long as possible. I don't want to deal with migrations any more often than we have to. While we're still pre 1.0, it would be good to not get into this.
Agree. If we can put it off, we should. I like only triggering deployment on certain tags, as long as we keep clear documentation so people know what to do. The only two additional things on my mind now are:
prisma migrate dev
?prisma migrate deploy
doesn't deal with drift, so no one should directly change schema of the prod database.I think you're both making great points. I wonder if we should decide to avoid all automatic schema updates pre-1.0, try hard to nail down the schema ASAP, and ask ourselves how to approach ongoing maintenance when we get to 1.0 (i.e, don't assume we'll do it).
This leaves another question that I need to answer ASAP: what does the manual process for creating/updating the databases on staging and production look like?
The Docker image we build for staging/production currently doesn't include the Prisma tools, schema, etc. I could add a build stage that does include this, and we could use that stage's image to manually run prisma db push
or whatever.
Help me think through the flow we'll use, since I need to do it in the next two weeks in order to get this up on staging.
I think it is going to be needed to do an automated (pre-scripted to be precise) migration method post-1.0
OK, I'll leave this open for 1.0, and wrote https://github.com/DevelopingSpace/starchart/pull/325 to try and do a manual solution for the 0.6-1.0.
Adding this to the 0.9 milestone, assigning to @cychu42
Plan/TODO:
db push --force
automatically so that we can do a dry-run of the update to the db before we go to production.DATABASE_SETUP
to make it more clear that it's dangerous. Use migrations by default instead.I'm think we might want to turn the prisma migrate dev
command into a script for future users.
Also, definitely tell people that they need to create migration files to affect staging and production in documentation, once migration is in place.
We've tested this on staging, and it's all working. Well done @cychu42.
In order to ship the app to staging(#43) we need to get ready to handle database migrations.
Currently, we are working with a development database locally, which can be blown away whenever we need to fix something. That won't work as soon as we move this to staging and production (hopefully in 0.5). In those cases, we'll have to create migrations and run them.
I am not an expert on this, but here is my current understanding of the problem and solution. Hopefully others will help with the research and implementation. I am basing this largely on the Prisma Migrate Mental Model:
prisma db push
to force the local development database to use our schema. This has been fine for development up to now, but won't work going forwardprisma migrate deploy
to run migrations against the database and synchronize it with our desired schema.prisma/migrations
, which are SQL files that describe transformations from one database state to another (e.g., adding a table, creating an index, etc). We do that usingprisma migrate dev --name init
.prisma migrate deploy
in prod to update our database (i.e., push schema and/or apply migrations).prisma migrate dev --name <name_of_migration>
. This SQL migration would then be applied in prod usingprisma migrate deploy
prisma migrate deploy
in our webhook deploy stepprisma migrate deploy
automatically in prod will require updates to our Dockerfile, in order to create an image layer that has the necessary dependencies and migrationsCONTRIBUTING
andDEPLOY
docsWhat else am I missing?
If we want to do any significant database schema changes before 1.0, it might be nice to do them before we set this baseline.
cc @cychu42, @dadolhay, @sfrunza13, @shawnyu5, who might all be interested in parts of this, or have thoughts. Anyone else is also welcome to take bits of this.