1. Go to this page and download the library: Download coenjacobs/migrator 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/ */
coenjacobs / migrator example snippets
namespace YourPlugin\Migrations;
use CoenJacobs\Migrator\Migrations\BaseMigration;
class CreateTestTable extends BaseMigration
{
public static function id()
{
return 'yourplugin-1-test-table';
}
public function up()
{
$tableName = $this->worker->getPrefix() . 'yourplugin_test';
$query = "CREATE TABLE $tableName (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
testvarchar VARCHAR(255) NOT NULL )";
$this->worker->query($query);
}
public function down()
{
$tableName = $this->worker->getPrefix() . 'yourplugin_test';
$query = "DROP TABLE $tableName";
$this->worker->query($query);
}
}
use CoenJacobs\Migrator\Handler;
use CoenJacobs\Migrator\Loggers\DatabaseLogger;
use CoenJacobs\Migrator\Workers\WpdbWorker;
$worker = new WpdbWorker();
$logger = new DatabaseLogger('migrations_table_name');
$handler = new Handler($worker, $logger);
use YourPlugin\Migrations\CreateTestTable
$migrator->add('yourplugin', CreateTestTable::class);
$migrator->up('yourplugin');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.