2

I have 2 environments for WordPress (dev && production), I'm working on dev env, when I add some new plugins, some will create tables or update configs in DB, how can I handle all these changes and then migrate to production env's DB?

I'm using git for file changes, but I can't handle the DB changes which created by plugins. How to integrate these changes in git? Or other workarounds?

  • I'm using a WordPress docker image, and I mounted an existing folder to /var/www/html

  • I upload the mounted folder to git for version control.

Except to manage all changes in version control tool.

Update:

I'm using wordpress 5.2.2.

How can I put a database under git (version control)? This one is the same. But looks like a little difference.

As this answer says, keep both data dump and schema dump. Is data dump have a correct diff info with previous? So that I can manually add this change to something like liquibase's changeset?

My concern is just the DB changes which changed by 3rd-part plugin, and I will hardly to trace.

lucky zhou
  • 101
  • 1
  • 7
  • Possible duplicate of [How can I put a database under git (version control)?](https://stackoverflow.com/questions/846659/how-can-i-put-a-database-under-git-version-control) – cabrerahector Jul 29 '19 at 14:00
  • Hi, could you please tell us which version of wordpress you are using? Last version of wordpress that I worked on was 4.x and because it didn't have db migration process, as a result handling db changes between environments were not possible out of the box. not sure whether it has changed in later versions. You can probably handle the table changes with a script, but if you're hoping syncing data between environments, I think that would require a lot more work or help of a plugin. – Tuhin Jul 29 '19 at 14:05
  • WordPress still doesn't have anything like migrations (as of version 5.2.2). My guess is that the OP is coming from a Laravel background, hence the use of the "migration" word here. – cabrerahector Jul 29 '19 at 17:06
  • thanks all! I have updated my question. – lucky zhou Jul 30 '19 at 01:30

1 Answers1

2

Here's is what we do. Any proper plug in will initialize new DB tables/fields on activation, and remove DB tables/fields when the plug-in is deactivated. In this way the plug in itself handles all DB migration functions. We write our plugins in this way, and nearly all plug-ins work in a similar fashion. We just commit plugin code to git, test in Dev, then release to production, and activate. Boom database is migrated. Nearly all database changes are driven by new plugins installation. Let it manage the database via it's own activate /deactivate hooks.

Rodrigo Murillo
  • 13,080
  • 2
  • 29
  • 50