Skip to content

Add Database Migrations

Database migrations manage changes in an application's database schema over time. Coherence offers universal support for migration tools.

Common migration tools

Common choices for migration tools include:

  • Built-in framework tools (for example, Django or Rails)
  • ORM tools (for example, Prisma)
  • Standalone tools (for example, Alembic)

Configuring database migrations in Coherence

To run database migrations as part of the deploy step in your Coherence pipelines, add the following migrate command to the x-cnc section for each service in your cnc.yml:

my-backend:
  x-cnc:
    type: backend
    migrate: "alembic upgrade head"

Note:

  • Only supported service types (such as backend) can use migrations.
  • Database migrations can currently only be configured by editing the YAML file in the cnc.yml tab, and cannot be set up using the service configuration form in the Coherence UI.
  • Migrations will run at the start of the deploy stage for the service, as part of the Coherence-managed build pipeline.
  • If migrations fail, they will fail the deploy stage, and the service won't update to the new version.
  • Migrations use the CNC toolbox internally.

YAML syntax

The migrate command can be defined in several ways.

All of the following examples are valid and interchangeable:

  • yaml migrate: "alembic migrate head"
  • yaml migrate: ["alembic", "migrate", "head"]
  • ```yaml migrate:
    • alembic
    • migrate
    • head ```