Skip to content

Deferred migrations system#175

Merged
Crypta-Eve merged 1 commit intoeveseat:5.0.xfrom
recursivetree:deferred-migrations
Feb 14, 2024
Merged

Deferred migrations system#175
Crypta-Eve merged 1 commit intoeveseat:5.0.xfrom
recursivetree:deferred-migrations

Conversation

@recursivetree
Copy link
Contributor

While working on a squad system update, I found a migration that depends on the business logic: https://github.com/eveseat/web/blob/fe45844ab67e68761720ce536d0ce481b4ff0f39/src/database/migrations/2020_12_06_220254_upgrade_squads_maj4_min4_hf2.php

This is a bad idea, since when the data the business logic operates on changes, the migrations breaks since the migration updating the data for the business logic didn't run yet. However, this migration is there to remove a broken state, so not running it is not an option.

The solution that this PR enables are deferred migrations: A migration can schedule a closure that should be run after all other migrations have completed. This means the data is already migrated to a state where the business logic is guaranteed to be able process it.

In a migration, using DeferredMigration::schedule, a migration can schedule a deferred migration:

public function up() {
   DeferredMigration::schedule(function(){
       //runs after all other migrations
   });
}

@Crypta-Eve Crypta-Eve merged commit 09d8b55 into eveseat:5.0.x Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants