Knowledgebase

Understanding Migrations Print

  • phplaravel, migration, database, backup, guide, howto, solution, zillionkinghost
  • 0

Schema as code.

WHAT A MIGRATION IS

A file describing a change to the database structure.

WHY USE THEM

The structure is versioned alongside the code Changes can be applied consistently across environments Anyone can recreate the structure from nothing

WHAT EACH CONTAINS

How to apply the change, and how to reverse it.

WHAT TO ALWAYS PROVIDE

The reversal, even when you expect never to use it.

WHAT TO NEVER DO

Modify a migration that has already run in production.

WHY

Environments diverge, and the record of what was applied becomes wrong.

WHAT TO DO INSTEAD

Write a new migration.

WHAT TO BE CAREFUL WITH

Migrations that alter large tables, which can lock them Migrations that also move data

WHAT TO DO ABOUT THE SECOND

Separate structural change from data change.

WHAT TO RUN BEFORE MIGRATING IN PRODUCTION

A backup.

WHAT TO TEST

Applying and reversing, on a copy.

WHAT TO CHECK AFTER

That the structure matches expectations.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot