liveBook · Manning

Migration

As explained in Developer Experience on Kubernetes

A database migration is a versioned change that transforms a database schema or data state in a controlled, repeatable way.

A database migration is a versioned, repeatable change to a database schema or data state. It supports evolutionary changes without breaking existing deployments: add new fields as optional, preserve existing reads and updates, and make them mandatory only after existing records are handled. section 2.3.2 section 2.4.2

A migration workflow typically follows these steps:

  • Write a numbered SQL migration that changes the schema. section 2.3.2
  • Configure a migration tool to discover and apply scripts in order at application startup. section 2.3.2 section 2.4.2
  • Update application records, queries, inserts, and reads to use the new field. section 2.3.2
  • Plan follow-up migrations for defaults or data conversion before enforcing new constraints. section 2.3.2

Adding an appointment category

Add migration 002_Appointment_add_category.sql with an up operation that adds a nullable category column and a down operation that removes it. Update the Appointment record and SQL statements so new appointments accept and return category values. Goose skips the migration when it has already been applied. section 2.3.2

Listing 2.4 Schema migration to add a new column to Appointments.
-- +goose Up
ALTER TABLE appointments ADD COLUMN category VARCHAR(255);
 
-- +goose Down
ALTER TABLE appointments DROP COLUMN category;

Inspect the reversible SQL migration that adds and removes the appointments category column. section 2.3.2

How Developer Experience on Kubernetes covers it

How deep it goes
Explains numbered SQL scripts, ordered startup application, repeat skipping, reversible operations, and deferred constraint enforcement.
Examples
Uses an appointments category column, Go structs and SQL queries, reversible Goose scripts, and a parallel Flyway implementation.
What it assumes
Assumes SQL and application data-model familiarity while teaching schema versioning and compatibility strategy through a feature change.
What you can do after
Operate/configure Goose or Flyway to apply a compatible schema change and align application code with it.
How it connects
Connects database schema, backward compatibility, application startup, Flyway, Goose, and data migration.

Also explained in

Compare how 23 books explain migration →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Developer Experience on Kubernetes. The section links point to the parts of the book it draws on.