[KongchangAI]
ConceptMigration / 数据库版本控制

Database Migration

A mechanism for version-controlling database schema changes, allowing development teams to manage the evolution of database table structures in a traceable and rollback-capable manner. It is a key practice in production-grade software engineering.

Core Facts

Timeline (last 90 days)

Oct 16

Distinguish between types of migration failure: a change with a structural error should be rolled back, while a change that is structurally fine but hit network jitter should be retried.

Unverified50%
Oct 16

A statement timeout should be set for every migration; without one, a migration competing for locks will block all queries on the table and drag down the entire application.

Unverified50%
Oct 16

Backfills should be processed in batches, avoiding locking a large number of rows (such as fifty thousand) in a single transaction.

Unverified50%
Oct 16

Renaming a column is actually two operations disguised as one, and the naive approach loses data on rollback; dropping a column has no honest down, because the data is already gone.

Unverified50%
Oct 16

During deployment there is a window in which old code and new code coexist, and the database may serve both versions simultaneously for anywhere from thirty seconds to two minutes.

Unverified50%
Oct 16

The core contract of a migration comes in pairs: up defines how to advance the structure to the new version, and down defines how to return to the previous version.

Unverified50%
Oct 16

A reliable set of migration conventions typically includes: timestamps in names to guarantee order, a ban on calling application model code inside migrations, explicitly declared lock strategies when operating on large production tables, and running a full up-down-up in the staging environment.

Unverified50%
Oct 16

The single rule that avoids most 3 a.m. incidents: additive migrations run before deployment, destructive migrations run after deployment.

Unverified50%
Oct 16

Rollback must take effect on the structure currently live, running no down migrations at all. If that is not possible, the migration order is wrong.

Unverified50%
Oct 16

For long backfills on large tables, if they fail midway due to a dropped connection, lock timeout or lagging replica, the migration should be made safe to re-run, using idempotent backfills (copying rows whose target is still empty) and retries with backoff and jitter, rather than rolling back.

Unverified50%

4 more timeline events

All Facts (14)

Verified

Migration is an engineering practice that manages database schema changes through versioned SQL scripts, which are traceable, rollback-capable, and can be consistently replayed across different environments.

75%
Unverified

Distinguish between types of migration failure: a change with a structural error should be rolled back, while a change that is structurally fine but hit network jitter should be retried.

50%
Unverified

Backfills should be processed in batches, avoiding locking a large number of rows (such as fifty thousand) in a single transaction.

50%
Unverified

Renaming a column is actually two operations disguised as one, and the naive approach loses data on rollback; dropping a column has no honest down, because the data is already gone.

50%
Unverified

During deployment there is a window in which old code and new code coexist, and the database may serve both versions simultaneously for anywhere from thirty seconds to two minutes.

50%
Unverified

The core contract of a migration comes in pairs: up defines how to advance the structure to the new version, and down defines how to return to the previous version.

50%
Unverified

A reliable set of migration conventions typically includes: timestamps in names to guarantee order, a ban on calling application model code inside migrations, explicitly declared lock strategies when operating on large production tables, and running a full up-down-up in the staging environment.

50%
Unverified

The single rule that avoids most 3 a.m. incidents: additive migrations run before deployment, destructive migrations run after deployment.

50%
Unverified

Rollback must take effect on the structure currently live, running no down migrations at all. If that is not possible, the migration order is wrong.

50%
Unverified

For long backfills on large tables, if they fail midway due to a dropped connection, lock timeout or lagging replica, the migration should be made safe to re-run, using idempotent backfills (copying rows whose target is still empty) and retries with backoff and jitter, rather than rolling back.

50%
Unverified

A statement timeout should be set for every migration; without one, a migration competing for locks will block all queries on the table and drag down the entire application.

50%
Unverified

The prerequisite for rollback is that operations are idempotent or transactionally guaranteed; database changes should prioritize migration scripts over direct SQL, and file changes should be included in version control.

50%
Unverified

Each migration script typically contains an up (forward change) and a down (rollback) operation, sorted by timestamp or sequence number.

50%
Unverified

Schema changes in production environments are high-risk operations: field type changes can cause existing data to become unparseable, and deleting columns results in permanent data loss.

50%

Source Articles