Edit

Nextras Migrations


Organizing Migrations#

Migrations are located in one or more directories (called groups). Unless configured otherwise, Nextras Migrations define three groups.

  1. structures
    • used for queries altering database structure (CREATE TABLE ..., ALTER TABLE ...) and for data migrations queries required to support the structural changes
  2. basic-data
    • used for queries which insert, update or delete basic data required to start the application
    • used for both development and production
  3. dummy-data
    • used for queries which insert, update or delete dummy data used when developing the application
    • used only for development

Migrations are executed in alphabetical order (by filename), e.g. structures/2015-03-17-aaa.sql is executed before dummy-data/2015-03-17-zzz.sql. The following structure is recommended and used by Symfony Console Commands by default:

migrations
├── basic-data                           # for both development and production
│   ├── 2015-03-16-170342-languages.sql  # YYYY-MM-DD-HHMMSS-label.extension
│   └── ...
├── dummy-data                           # for development on localhost
│   ├── 2015-03-17-104235-users.sql
│   └── ...
└── structures                           # create, alter tables...
    ├── 2015-03-17-155419-users.sql
    └── ...

Optionally you can use deep directory structure which is suitable if you have a lot of migrations:

migrations/
├── basic-data/
│   └── 2015/
│       ├── 03/
│       │   ├── 2015-03-16-170342-languages.sql
│       │   └── ...
│       └── 04/
│           └── ...
└── ...

Writing Migrations#

Migrations can written as file with any extension that has defined extension handler. The two built-in extension handlers are SQL and PHP. Migrations can be written manually or generated through diff generator. The only built-in diff generator is a structures generator for Doctrine.