Skip to content
Snippets Groups Projects
Verified Commit bb0b7d28 authored by Bartek Jaskulski's avatar Bartek Jaskulski
Browse files

feat: add support for conditional execution of migrations


Signed-off-by: default avatarBart Jaskulski <bjaskulski@protonmail.com>
parent 0d1066b2
No related branches found
No related tags found
1 merge request!1is needed
......@@ -20,5 +20,12 @@ abstract class AbstractMigration {
abstract public function up(): bool;
public function down(): void {}
/**
* Allow to skip migration if it is not needed. Tracking of migration version just by wp_options
* value may be subject to random issues, so as a backup, this method can be used to avoid
* errornous migrations like creating alredy exising columns.
*/
public function is_needed(): bool {
return true;
}
}
......@@ -133,7 +133,12 @@ class WpdbMigrator implements Migrator {
$this->logger->info( sprintf( 'DB update %s:%s', $current_version, $migration->get_version() ) );
$success = $migration->get_migration()->up();
$success = null;
if ( $migration->get_migration()->is_needed() ) {
$success = $migration->get_migration()->up();
} else {
$success = true;
}
if ( $success ) {
$this->logger->info( sprintf( 'DB update %s:%s -> ', $current_version, $migration->get_version() ) . 'OK' );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment