Migrations execution will be subject of differences depending on development environment (eg: using db connection settings). It will thus require environment variable ENVIRONMENT to be already set:
export ENVIRONMENT={VALUE}
setx ENVIRONMENT {VALUE}
If above is not set, framework automatically assumes {VALUE} will be local!
API requires a Lucinda\Migration\Cache implementation for keeping track of migrations that ran already as well as their outcome. Framework Skeleton API comes with:
CREATE TABLE migrations
(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
class_name VARCHAR(255) NOT NULL,
is_successful BOOLEAN NOT NULL DEFAULT TRUE,
date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY(id),
UNIQUE(class_name)
) Engine=INNODB
Lucinda\Project\DAO\SQLMigrationCache is used by default in migrations.php:
define("CACHE_TYPE", "sql");
If you want to switch to the other, you only need to edit migrations.php and change line to:
define("CACHE_TYPE", "nosql");
To generate a migration script, open console and run:
php migrations.php generate
This will create a VersionTIMESTAMP class (eg: Version20210205105634) in migrations folder, implementing Lucinda\Migration\Script and coming with two methods:
Example implementation:
class Version20210205105634 implements \Hlis\Migration\Script
{
/**
* Commits changes
*/
public function up(): void
{
SQL("ALTER TABLE users ADD age TINYINT UNSIGNED NOT NULL DEFAULT 0");
}
/**
* Rolls back changes
*/
public function down(): void
{
SQL("ALTER TABLE users DROP COLUMN age");
}
}
migrations.php allows you to execute migrations using multiple strategies through console arguments:
php migrations.php migratephp migrations.php up Version20210205105634php migrations.php down Version20210205105634Depending on Lucinda\Migration\Cache solution chosen, migration progress will be saved to a permanent storage medium that makes sure: