mirror of
https://github.com/storytold/artcraft.git
synced 2026-10-20 17:02:53 -04:00
1.2 KiB
1.2 KiB
SQL Migrations
Incremental schema changes applied in order by timestamp prefix.
Naming Convention
Migration directories follow the format:
YYYY-MM-DD-HHMMSS-NNNN_description_goes_here/
up.sql
down.sql
These are created with the diesel tool, and in particular:
diesel migration generate description_goes_here
NNNNis a zero-padded sequence number for ordering multiple migrations on the same timestamp.up.sqlapplies the migration forward.down.sqlreverses it.
Table Conventions
- Primary key
idcolumns must beBIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT. Do not use signed IDs. - Always create tables with
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin. - All SQL files should start with the standard IntelliJ noinspection comments:
-- noinspection SqlDialectInspectionForFile -- noinspection SqlNoDataSourceInspectionForFile -- noinspection SqlResolveForFile
Rules
- Every
up.sqlmust have a correspondingdown.sqlthat cleanly reverses the migration. - For
CREATE TABLEmigrations, thedown.sqlis typicallyDROP TABLE IF EXISTS table_name;. - For
ALTER TABLEmigrations, thedown.sqlreverses the alteration (e.g.DROP COLUMN).