We have a large Yii2 / PHP application using MySQL database and versioned by GIT. The application is under continuous development as customer require new features. The database gets changed quite frequently. The application is versioned using GIT (each production version gets a new GIT tag) and backuped on a daily basis.

When something fails we need to restore one of our latest database backups. Sometimes in case if database problems the restore fails because of recent application updates. And the other way round (this was not yet the case, luckily!): if the application fails (e.g. the server gets hacked) we need to know which GIT tag the database belongs to.

How can we assure that the database and the application are in sync?

Are there scripts or best practices around?

BTW: We don't want to include the database backup in the git versioning (see here)

  • No, we don't want to do that as I explicitly remarked. We just want our app and the database always being synched during restore. Is the question too unclear in that point? – WeSee Dec 10 '15 at 8:56

This is typically done by adding some logic to the application. When the application is started, it should check if the database schema is compatible (e.g. by putting the tag in some database table). If the database schema is too old for that release of the application, the application can automatically apply the required migration scripts. If the database schema is too recent, the application should refuse to work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.