Schema Versioning

Schema versioning is a critical practice in managing database changes. It allows you to track and control updates to your database schema, ensuring compatibility and minimizing potential disruptions. This page explains the concepts and best practices.

Key Concepts

Here are the core ideas behind schema versioning:

Benefits of Versioning

Using schema versioning offers numerous advantages:

Example Migration Script (SQL)
-- Version 1: Initial schema CREATE TABLE users ( id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255) NOT NULL, email VARCHAR(255) UNIQUE ); -- Version 2: Add a 'status' column ALTER TABLE users ADD COLUMN status ENUM('active', 'inactive') DEFAULT 'active';

This example demonstrates how a migration script can be applied in a series of versions. Each `ALTER TABLE` statement represents a new version.