POLAKO / Blog

Databases · 22.11.2026

Database migrations: why they belong in your CI/CD pipeline

Code ships automatically, but the database is often changed by hand, “quickly, in production”. That's where most nasty surprises come from.

A migration is a script that changes the database structure: adds a column, a table or an index, changes a data type. The application and the database must agree – the new version of the code expects the new structure. Ship one without the other and the site goes down.

How it usually looks

A developer ships the new app version through an automated process, but runs the database change by hand – from their laptop, in a terminal, “just this once”. Sometimes they forget. Sometimes they run it against the wrong database. Sometimes the test and production databases have quietly drifted apart and nobody knows exactly why.

What you get when CI/CD runs migrations

  • The same order everywhere. Every migration is a versioned file in the repository. Test, staging and production go through the same steps, in the same order.
  • Test first, then production. The pipeline runs migrations against a copy of the database and runs the tests. If something breaks, it breaks in test, not in front of customers.
  • Code and schema ship together. The new app version isn't released until the migration has succeeded.
  • An audit trail. You know who changed what, when and why – through code review, like any other code.
  • No personal access to production. Nobody needs the production database password on their laptop. Only the pipeline has access.

What to watch out for

  • A backup before every migration – automatically, as a pipeline step.
  • Changes that don't break the old version. Add the new column first, ship code that uses it, and only then drop the old one. That way you can roll back the app without taking the site down.
  • Large tables. Adding an index to a table with millions of rows can lock the database. Such migrations are planned and run in a non-blocking way.
  • A way back. For every migration you should know how to undo it – or why you won't, and will roll forward with a fix instead.

There are tools for almost every language and database – Flyway, Liquibase, Prisma, Drizzle, Alembic, Laravel migrations. The tool matters less than the rule: nobody changes the production database by hand.

Want to know where your site's limit is?

Audit from €990, fixed price. We start by asking how you run things today.

Request an audit →

Blog

Read more

Basics

QA, environments and Gitflow: getting code to production without surprises

Customers only ever see one environment – production. Three more sit backstage, and that's where all the work and all the mistakes should happen. The basics any team can introduce step by step.

Read →
Architecture

Message queues: why ticket checkout and chat shouldn't hang on a single call

SNS, SQS and similar message queues split a system into parts that don't fail together. And when something goes wrong, there's a trail: what happened, in what order, and when.

Read →
High traffic

Ticket drops, launches, flash sales: surviving the second everyone clicks at once

A concert ticket drop or a product launch is the hardest test a system can face. It isn't decided by one server but by a set of decisions made in advance – and at the centre there's almost always a distributed Redis.

Read →
Architecture

A fast site starts with understanding the browser

What to load first, what can wait, what's static and what really has to be computed per visitor. The decisions that decide speed – and whether a site survives peak traffic.

Read →
Good practice

A portal that survives peak traffic: 6 good practices for classifieds and news sites

Classifieds and news portals share a similar architecture – and similar weak spots. Here are six things we check first, and how to fix them.

Read →
Basics

What DevOps actually does – one August, as an example

DevOps engineers are the reason a site stays up when everyone arrives at once. Here is what that looks like in practice.

Read →
Audit

Why an audit pays off before the season, not after

You can learn your system's limit in two ways: in advance, calmly – or mid-season, from your customers.

Read →
Security

What a web application firewall is – and who needs one

A web application firewall (WAF) is a guard at the gate: it lets guests in and stops those who come to do damage.

Read →
Reliability

A backup you've never restored isn't a backup

Most companies have backups. Far fewer have ever checked whether they can be restored.

Read →