byjg / php-migration

Simple library writen in PHP without framework dependancy for database version control. Supports Sqlite, MySql, Sql Server and Postgres
MIT License
155 stars 27 forks source link

how create migrate? #21

Closed Driver86 closed 4 years ago

Driver86 commented 4 years ago
<root dir>
     |
     +-- base.sql
     |
     +-- /migrations
              |
              +-- /up
                   |
                   +-- 00001.sql
                   +-- 00002.sql
              +-- /down
                   |
                   +-- 00000.sql
                   +-- 00001.sql

How create migrate? For example, I made changes to the database. How do I create these files 00001.sql, 00002.sql?

byjg commented 4 years ago

This files 00*.sql should contain all sql commands necessary to migrate your database from one version to another. Unfortunately it is not created automatically.

My suggestion is every SQL command you use to change your database save in the file of the version. Create also the file for migrate down, and try to migrate UP and DOWN to make sure everything is fine.

If your database is MySQL and you are using Mysql Workbench tool to make changes on your database you can get the exact SQL commands to update your database.