Skip to content

Migrations

This page describes how database migrations are handled across services.

Migrations ensure that database schema changes are versioned, reproducible, and safely applied across environments.

  • Each service owns its own migrations
  • Migrations must not span across service boundaries

Database migrations must:

  • Be version-controlled
  • Be applied in a deterministic order
  • Be safe to run across multiple environments
  • Represent incremental schema changes

Manual changes directly in shared environments must be avoided.

When creating a new service or changing an existing schema, migrations must be used to describe the change.

Each migration should:

  • Perform a single logical change
  • Be easy to understand when read in isolation
  • Avoid bundling unrelated schema changes together

When creating a new service with a database:

  • Define the initial schema using migrations
  • Ensure the schema can be fully recreated from migrations alone
  • Do not rely on manual bootstrap scripts

The goal is that a new environment can be set up by applying migrations from an empty database.

Migrations should be applied automatically as part of the service lifecycle.

Typical environments where migrations are applied:

  • Local development
  • CI pipelines
  • Test and staging environments
  • Production (in a controlled manner)

Migrations should be applied by automation (pipelines or runtime), not manually.

Migrations are applied in the order they are created.

Guidelines:

  • Never modify an existing migration that has been applied
  • New changes must always be added as new migrations
  • Avoid dependencies between migrations across services

Changing an already applied migration can lead to inconsistent environments.

Migrations should be designed with rollback and backward compatibility in mind.

Guidelines:

  • Avoid destructive changes when possible
  • Consider transitional states when removing columns or tables
  • Ensure application code can handle both old and new schemas during deployment

All migrations must be:

  • Reviewed as part of code review
  • Tested locally before merging
  • Applied in a test environment before production

Schema changes should be treated with the same care as application code.