Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
Wp Migrations
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wpdesk
Library
Wp Migrations
Commits
bb0b7d28
Verified
Commit
bb0b7d28
authored
6 months ago
by
Bartek Jaskulski
Browse files
Options
Downloads
Patches
Plain Diff
feat: add support for conditional execution of migrations
Signed-off-by:
Bart Jaskulski
<
bjaskulski@protonmail.com
>
parent
0d1066b2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1
is needed
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/AbstractMigration.php
+8
-1
8 additions, 1 deletion
src/AbstractMigration.php
src/WpdbMigrator.php
+6
-1
6 additions, 1 deletion
src/WpdbMigrator.php
with
14 additions
and
2 deletions
src/AbstractMigration.php
+
8
−
1
View file @
bb0b7d28
...
...
@@ -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
;
}
}
This diff is collapsed.
Click to expand it.
src/WpdbMigrator.php
+
6
−
1
View file @
bb0b7d28
...
...
@@ -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'
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment