Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagephp
[...]
echo "Updating database structures...\n";
$controller->forwardEngineerAllModules();

NewFrontiers\Modules\DatabaseMigration\DatabaseMigrationController::runUpdate();
[...]

Migration files

Put your migration files into ./src/migrations/ (Environment::get()->migrationDir). Migration files are simple SQL files consisting of SQL statements. The statements have to be separated with semicolons.

Please make sure your SQL statements are as generic as can be, so that your customer database and your test database can get migrated without problems.

Migration file example

Code Block
languagesql
INSERT INTO `user` (us_benutzername) VALUES ('username');
UPDATE `user` SET us_aktiv = 1 WHERE us_benutzername = 'username';

Migration file commands

In version 6.5.6, new SQL comment based commands were added, so that it is possible to write different SQL statements for each database management system. Available statements are:

  • --switch engine;
  • --case ______;
  • --end;

It is very important to put semicolons behind each statement. Else they will act as regular comments.

The following example should explain the whole concept:

Code Block
languagesql
[...]
--switch engine;
  --case sqlite;
    UPDATE `user` SET us_aktiv = 1 WHERE us_benutzername = 'username';
  --case mysql;
    UPDATE `user` SET us_aktiv = 2 WHERE us_benutzername = 'username';
--end;
[...]

(The indention is not necessary.)

Troubleshooting (working with comments)

At the moment, it is not use comments before a command statement. It will result in ignoring the statements. Example:

Code Block
languagesql
[...]
/* This will cause an error. */
--switch engine;
[...]
/* Appending a semicolon after the comment will fix it. */;
--switch engine;

...