Skip to main content

Schema migrations

Compare deux connexions, genere le DDL pour les aligner, lint les migrations, applique avec rollback.

Quand l'utiliser

  • Aligner staging sur prod avant un deploiement.
  • Generer une migration depuis un changement fait en local sur une DB de travail.
  • Auditer les changements DDL avec Annotation rattachee.

Differe de Mass Patch : ici on touche au schema (DDL), pas aux donnees.

Workflow rapide

  1. Migrations -> Nouvelle migration.
  2. Source = connexion "verite" (ex : dev a jour). Cible = connexion a aligner (ex : staging).
  3. Auralith compare via schema_migration_service. Genere le DDL de reconciliation (CREATE TABLE / ALTER / CREATE INDEX / DROP TABLE etc.).
  4. Lint via migration_linter : warnings sur les operations couteuses (ALTER COLUMN sur grosse table, ADD COLUMN NOT NULL sans default).
  5. Reviewer manuellement le SQL. Editer si besoin.
  6. Appliquer. Auralith execute en une transaction (sauf operations DDL non transactionnelles selon dialecte).
  7. Rollback automatique disponible si la migration a ete generee avec rollback DDL.

Concepts cles

  • Migration : enregistrement (id, project_id, source_connection_id, target_connection_id, generated_sql, lint_warnings, applied_at).
  • Migration linter : detecte patterns risques (ALTER COLUMN type, ADD NOT NULL sans default sur table peuplee, DROP COLUMN avec FK).
  • Rollback DDL : genere quand possible (CREATE -> DROP, ADD COLUMN -> DROP COLUMN). Pas de rollback pour DROP COLUMN sans backup.

Pieges courants

  • DDL non transactionnel : sur MySQL, beaucoup de DDL sont auto-commit. Une migration partiellement appliquee ne se rollback pas. Postgres / MSSQL sont mieux loties.
  • ADD COLUMN NOT NULL sans default sur grosse table : verrou de table long. Le linter vous avertit. Solution : ADD nullable, backfill via Mass Patch, ALTER NOT NULL.
  • DROP TABLE / DROP COLUMN : irreversible. Auralith demande double confirmation. Snapshot via Drift detection avant l'application.

API

# Comparer
curl -X POST https://app.auralith.io/api/v1/projects/{pid}/migrations/compare \
-d '{"source_connection_id":"...","target_connection_id":"..."}'

# Appliquer
curl -X POST https://app.auralith.io/api/v1/migrations/{id}/apply

Voir aussi