liveBook · Manning

Data migration

As explained in Unit Testing Principles, Practices, and Patterns

Data motion is the transfer, transformation, or relocation of existing data required during a database change.

Data motion changes the shape of existing data so that it conforms to a new database schema. Unlike schema changes, these transformations depend on domain-specific rules because data is context-dependent. section 10.1

Explicit migrations handle data motion more reliably than state-based comparison tools. State-based delivery makes schema state explicit and migrations implicit; migration-based delivery makes each transition explicit. section 10.1 section 10.7

Splitting a name column

Replacing Name with FirstName and LastName requires more than dropping one column and creating two others. A migration must also split every existing name according to appropriate domain rules. section 10.1

Use these rules when database changes must preserve existing data:

  • Prefer explicit migrations after the application reaches production, when existing data cannot simply be discarded. section 10.1
  • Apply every schema modification, including reference-data changes, through migrations. section 10.7
Figure 10.2. The migration-based approach to database delivery emphasizes the use of explicit migrations that transition the database from one version to another.

Shows explicit migrations transitioning a database from one version to another, the delivery mechanism used to manage data motion. section 10.1

How Unit Testing Principles, Practices, and Patterns covers it

How deep it goes
Defines data motion, contrasts delivery approaches, and demonstrates a column split without detailing transformation algorithms.
Examples
Uses splitting Name into FirstName and LastName as the central transformation example.
What it assumes
Assumes database schema changes and distinguishes released production data from disposable test data.
What you can do after
Apply it via explicit migrations that transform existing data alongside schema changes.
How it connects
Connects database schema changes with database migrations, state-based delivery, reference data, and domain-specific transformation rules.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Unit Testing Principles, Practices, and Patterns. The section links point to the parts of the book it draws on.