PHP code example of console-helpers / db-migration
1. Go to this page and download the library: Download console-helpers/db-migration library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
console-helpers / db-migration example snippets
use ConsoleHelpers\DatabaseMigration\MigrationManager;
use ConsoleHelpers\DatabaseMigration\PhpMigrationRunner;
use ConsoleHelpers\DatabaseMigration\SqlMigrationRunner;
use Pimple\Container;
// 1. Create migration manager instance.
$migration_manager = new MigrationManager(
'/path/to/migrations', // Directory containing migrations.
new Container() // Anything implementing "ArrayAccess".
);
// 2. Register migration runners.
$migration_manager->registerMigrationRunner(new SqlMigrationRunner());
$migration_manager->registerMigrationRunner(new PhpMigrationRunner());
use ConsoleHelpers\DatabaseMigration\MigrationManager;
$migration_name = $migration_manager->createMigration(
'example_migration', // any valid filename
'sql' // 'php' or 'sql' (comes from migration runner)
);
use ConsoleHelpers\DatabaseMigration\MigrationContext;
return function (MigrationContext $context) {
// Write PHP code here.
};
use Aura\Sql\ExtendedPdo;
use ConsoleHelpers\DatabaseMigration\MigrationManager;
use ConsoleHelpers\DatabaseMigration\MigrationContext;
use Pimple\Container;
// 1. Create database connection.
$database = new ExtendedPdo('sqlite:/path/to/database.sqlite');
// 2. Run migrations.
$migration_manager->runMigrations(
// Context consists of the database and container.
new MigrationContext($database)
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.