The expand and contract pattern enables zero-downtime database schema migrations by deploying new structures alongside existing ones, gradually transitioning clients through seven discrete steps: deploy new schema, expand client writes to both structures, migrate existing data, test the new interface, switch reads to new structure, stop writing to old structure, and finally remove the original schema. This approach allows safe rollback at most stages and is demonstrated through a practical example of refactoring playground equipment tracking from embedded columns to a separate table structure.

13m read timeFrom prisma.io
Post cover image
Table of contents
Step 1: Build and deploy the new schemaStep 2: Expand the interfaceStep 3: Migrate existing data to the new schemaStep 4: Test the new interfaceStep 5: Cut reads over to the new interfaceStep 6: Discontinue writing to the original structureStep 7: Remove the original structure from the system

Sort: