diff --git a/src/AbstractMigration.php b/src/AbstractMigration.php index 7a827027b656318e3b28e7148df98d3c90f33c7a..a83514d98901369c90a2808d34b04c3d50efe46a 100644 --- a/src/AbstractMigration.php +++ b/src/AbstractMigration.php @@ -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; + } } diff --git a/src/WpdbMigrator.php b/src/WpdbMigrator.php index d35821f4cda842760a14c975ba08e5f478e88075..bf896e1cd13a79b3e8ece70ba5590e7f0bbcd5d9 100644 --- a/src/WpdbMigrator.php +++ b/src/WpdbMigrator.php @@ -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' );