database migration
A scripted, versioned change to a database's structure, such as adding a table or a constraint.
In more detail
Migrations are applied in order and kept with the application code so every environment ends up with the same schema. Tools record which migrations have already run, so each environment applies only the ones it is missing.
Examples
In AWS: A planned change to a database’s structure or data, such as adding a column, applied in a controlled order.dotnet ef migrations add InitialCatalogdotnet ef database updateIn the browser: In IndexedDB, migrations run in onupgradeneeded, checking the old version number and applying each step needed to reach the new one.Moving to a normalised design is done as a migration that adds the new tables and constraints together.In this course: Migrations can only be proven by running them against the real engine, so a container-based test that applies them from scratch is valuable. Run the same migrations in tests that production runs, so a broken migration fails the build instead of a deployment.Related terms
- schema — A formal description of the structure of data: which fields or columns exist, their types and which are required.
- rollback — Returning a system to a previous known-good version after a bad change.
- Amazon RDS — Amazon Relational Database Service, which runs relational database engines such as PostgreSQL and MySQL as a managed service.
- admin process — A one-off task, such as a database migration, console session or repair script, run as its own process against the same release as the app.
- backward compatibility — The property that a new version of an interface still works for clients written against the old one.
- fix forward — Recovering from a bad change by quickly shipping a new fix, instead of going back to the previous version.
- code first — An approach in which the C# entity classes are the source of truth for the database model and migrations generate the schema from them.
- dotnet ef — The EF Core command-line tool for creating and applying migrations, installed as a dotnet tool and used with the Design package in the project.
- model snapshot — A generated file recording EF Core's view of the current model, compared with the entities to work out what the next migration must change.
- upgradeneeded event — The IndexedDB event fired when a page opens a database with a higher version number than the stored one, the only place the schema can change.
- expand-and-contract — A way to change a live database in safe steps: add the new structure, move data and code to it, then remove the old structure.
- zero-downtime deployment — Releasing a new version while users keep being served, with no period where the service is unavailable.
- Testcontainers — A family of libraries that start real dependencies such as databases in throwaway containers for the length of a test.
- CREATE TABLE — The SQL statement that defines a new table: its name, columns, types and constraints.
- live migration — Moving data or traffic to a new home while the system keeps serving requests.
- database engine — The database software itself, such as PostgreSQL, MySQL or SQLite, which decides the features, SQL dialect and extensions available.
- integration test — A test that checks several real parts working together, such as the service talking to a real database.
Taught in
- Deploying With Less Downtime — Microsoft Azure DevOps Engineer Expert (AZ-400) Exam Prep
- The Danger of Long-Lived Keys — Cloud Infrastructure & Hyperscaler Architecture
- S3: Buckets and Objects — Cloud Infrastructure & Hyperscaler Architecture
- Managed Relational Databases (RDS) — Cloud Infrastructure & Hyperscaler Architecture
- Restoration: Failed Deployment Recovery Time — DevOps & Site Reliability Engineering
- Build, Release, Run And Processes — DevOps & Site Reliability Engineering
- Admin Processes And The Open Source Update — DevOps & Site Reliability Engineering
- Continuous Delivery Versus Continuous Deployment — DevOps & Site Reliability Engineering
- Deployment Strategies: Rolling Updates — DevOps & Site Reliability Engineering
- Entity Framework Core: Code First and Migrations — Modern .NET Core, C# & Enterprise Microservices
- Querying, Change Tracking, and Saving Data — Modern .NET Core, C# & Enterprise Microservices
- IndexedDB In Practice: Object Stores, Indexes And Transactions — Frontend Architecture & Web Platform
- Service Worker Lifecycle: Installation, Activation And Update — Frontend Architecture & Web Platform
- Database Access & Migrations: ORM & Data Layers — Production Full-Stack Engineering
- Persistence With JPA And Hibernate — Modern Java: Virtual Threads & High-Throughput Services
- Database Integration With Testcontainers — Modern Java: Virtual Threads & High-Throughput Services
- Tying It All Together — Modern Java: Virtual Threads & High-Throughput Services
- Normalisation To Third Normal Form — PostgreSQL, Indexing & Relational Data Modeling
- The Storage Decision: Relational Versus Document — Scalable System Design & Distributed Architecture
- Partitioning, Sharding And Hot Keys — Scalable System Design & Distributed Architecture
- Cache Invalidation And The Three Hard Cases — Scalable System Design & Distributed Architecture
- Integration Testing With Containers — Automated Testing, TDD & Quality Engineering
- Testing With Real Databases — Automated Testing, TDD & Quality Engineering
References
- PostgreSQL documentation: Modifying Tables
- Martin Fowler and Pramod Sadalage: Evolutionary Database Design
- DORA capability: database change management
- Migrations overview (EF Core)
- Prisma: Migrate
- Flyway documentation
- Spring Boot: Use a Higher-level Database Migration Tool
- PostgreSQL documentation: Table Basics
- Alembic tutorial