P
P
pantsarny2015-09-13 12:22:37
PHP
pantsarny, 2015-09-13 12:22:37

How to create SQL migration with Git commit?

Good afternoon, colleagues. I would like to ask you how you "hook" the necessary sql to git commits? The situation is a small team of developers, with a completed task (php), a commit goes to git, but the task could have changes in the structure of the database (mysql). How do you create commit-linked migrations?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Volintsev, 2015-09-13
@pantsarny

On the example of the Yii framework
www.yiiframework.com/doc/guide/1.1/ru/database.mig...
www.yiiframework.com/doc-2.0/guide-db-migrations.html
www.youtube.com/watch?v =cugnRoZ1ick&feature=youtu.be
Migrations are classes in PHP. They are hosted in git.
The migration class contains a method for upgrading (rolling forward) and downgrading (rolling back) changes.
The database has a table with a list of installed migration files.
When installing or updating a project, a special command analyzes the directory with migration files (there may be several of them), checks against the table.
Offers to install (roll) those migration files that are not in the database.
You can ask to cancel (roll back) the change or install it again.
In migration, you can change the structure of the table (model migration), and change the data (data migration).
In our installation script (on the toaster: What workflow front-end do you have? ) we make a backup of the database before and after the update. There is a manual rollback script to restore the database.
And in the ideal case, you should try to write the code in such a way that it can work without failures with both the old and the new base model.

O
OnYourLips, 2015-09-13
@OnYourLips

How do you create commit-linked migrations?

I create a migration and comic it.
Want to know more about the tools you use?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question