feat: migration squashing#1152
Merged
thetutlage merged 8 commits into22.xfrom Mar 19, 2026
Merged
Conversation
thetutlage
reviewed
Mar 13, 2026
thetutlage
reviewed
Mar 13, 2026
thetutlage
reviewed
Mar 13, 2026
Member
|
Let's get it in. Great work @Julien-R44 👏 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AI-Generated PR Summary
This PR adds Laravel-style migration squashing to Lucid
It introduces a new
schema:dumpcommand that exports the current database schema to SQL, stores Lucid migration metadata alongside it, and allows futuremigration:*commands to bootstrap a fresh database from that dump instead of replaying the full migration history.Support MySql, Postgres and Sqlite only
High-level flow
The feature is designed around a rolling schema baseline.
Typical flow:
schema:dump --prune..meta.jsonmanifest.On a fresh database,
migration:runnow:adonis_schema)The same cycle can be repeated multiple times:
Each new dump becomes the new baseline. The manifest is regenerated from the current contents of
adonis_schema, so it naturally absorbs:This means re-squashing is a first-class workflow, not a one-time operation.
What is included
schema:dumpcommandmigration:runwhen:updryRunis disabled--schema-pathsupport inmigration:runandmigration:fresh--prunesupport inschema:dump.meta.jsonmanifest stored next to the SQL dumpmigration:statusmigration:rollbackmigration:resetmigration:refreshDatabaseTestUtilsWhy the manifest exists
Laravel is permissive when previously-ran migration files disappear from disk. Lucid has historically treated that as a corruption signal.
To preserve that stricter behavior while still supporting squashing, this PR adds a schema dump manifest that records the migrations intentionally absorbed into the dump.
That allows Lucid to distinguish between:
squashed: migration file was intentionally pruned after schema dumpcorrupt: migration is missing unexpectedlyThis keeps the current integrity signal useful instead of disabling it globally.
Command behavior
schema:dumpGenerates:
database/schema/<connection>-schema.sqldatabase/schema/<connection>-schema.meta.jsonThe SQL dump includes:
adonis_schemaadonis_schema_versionsWith
--prune, Lucid deletes the configured migration directories after the dump succeeds.This assumes configured migration paths are dedicated migration directories.
migration:runWhen the target database is fresh and a dump exists, Lucid now:
If no dump exists, Lucid falls back to the existing migration flow.
migration:statusStatus output now includes a new
squashedstate for migrations that were previously run, are no longer on disk, and are listed in the dump manifest.Missing migrations that are not part of the manifest remain
corrupt.migration:rollback/migration:resetRollback and reset now skip missing migrations that are marked as
squashed, while continuing to fail for truly missing / corrupt migrations.This mirrors Laravel's tolerance for pruned historical migrations, but keeps Lucid's stricter semantics for accidental history drift.
Test utilities
This PR also ensures Lucid's test helpers continue to work after squashing.
DatabaseTestUtilsnow behaves correctly with schema dumps and pruned migrations because the underlying migration commands are squash-aware.