sinevia/php-library-migrate

v1.4.0 2020-01-12 07:07 UTC

This package is auto-updated.

Last update: 2024-11-12 18:47:49 UTC


README

How to Use

  1. Create a migration directory to hold your migration files

  2. Create the migration files with the following format YYYYMMDD_SEQNCE_ClassName (i.e. 20180905_000001_CreateSettingsTable).

class CreateSettingsTable {
    /**
     * Run the migrations.
     *
     * @return void
     */
    function up() {
        // YOUR CODE HERE
    }
    
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    function down() {
        // YOUR CODE HERE
    }
}
  1. Create a migrate.php file at a location of your preference (this example uses "app/migrate.php"). The migrations will be sorted alphabetically in ascending order and run
require_once dirname(__DIR__) . '/vendor/autoload.php';

db()->debug = true; // if you want to trace what is going on

Sinevia\Migrate::setDirectoryMigration(__DIR__.'/Migrations');
Sinevia\Migrate::setDatabase(db());
Sinevia\Migrate::up();

Run the migrations:

php app/migrate.php