FacturaScripts

MigrationClass
in package

AbstractYes

Template class for plugin migrations

This class serves as a base for creating plugin-specific migrations that will be executed only once and tracked in MyFiles/migrations.json to prevent re-execution.

Usage example:

In your plugin's Migrations directory, create a migration class:

namespace PluginName\Migrations;

use FacturaScripts\Core\Template\MigrationClass;

class FixUsersTable extends MigrationClass { const MIGRATION_NAME = 'fix_users_table_v1.2.0';

public function run(): void
{
    if (!$this->db()->tableExists('users')) {
        return;
    }

    $sql = "ALTER TABLE users ADD COLUMN new_field VARCHAR(50)";
    $this->db()->exec($sql);
}

}

Then in your plugin's Init.php update() method:

use FacturaScripts\Core\Migrations; use FacturaScripts\Plugins\PluginName\Migrations\FixUsersTable;

public function update(): void { Migrations::runPluginMigration(new FixUsersTable()); }

Table of Contents

Constants

MIGRATION_NAME  = ''
Migration name identifier. Must be unique within the plugin.

Properties

$database  : DataBase

Methods

db()  : DataBase
Get database instance
getFullMigrationName()  : string
Returns the unique migration identifier including plugin name
getMigrationName()  : string
Returns the migration name
getPluginName()  : string
Returns the plugin name from the class namespace
run()  : void
Execute the migration logic

Constants

MIGRATION_NAME

Migration name identifier. Must be unique within the plugin.

public mixed MIGRATION_NAME = ''

It should be descriptive and include version/date information. Example: 'my_plugin_fix_users_table_v1.2.0'

Properties

Methods

getFullMigrationName()

Returns the unique migration identifier including plugin name

public static getFullMigrationName() : string
Return values
string

getMigrationName()

Returns the migration name

public static getMigrationName() : string
Return values
string

getPluginName()

Returns the plugin name from the class namespace

public static getPluginName() : string
Return values
string

        
On this page

Search results