Skip to content

<div style="display: none;" hidden="true" aria-hidden="true">Are you an LLM? You can read better optimized documentation at /guides/Migrations.md for this page in Markdown format</div>

Home | Changelog

Migrations

Changelog

v1.0.3 - initial for adveshop 4

Migration package is ecommmercen/v4-migrations

It is a wrapper for Phinx with dependencies applicable for adveshop4.

Phinx migrations support raw sql which we use for convenience (no need to learn another query builder - and more compatible with current flow).

You can read more info in it's documentation

All phinx commands are registered in package and available to client. configuration is at /phinx.php

Usage

To execute migrations run php migrator.php migrate

To create a new migration run php migrator.php create MigrationTask. A new file will be created in database/migrations with a class with up and down methods.

Example of up function

public function up(): void {
    $this->execute('ALTER TABLE `table` ADD COLUMN `new_column` VARCHAR(255) NOT NULL');
}

If the migration is to be used as a patch the created migration class should extend \Patches\Patcher and have protected property protected string $class = \Patches\PatchClass::class

To create a new seeder run php migrator.php seed:create SeedNewColumn. A new file will be created in database/migrations with a class with run method.

Example from InitialSeeder code (show usage of read / write)

$currencies = $this->table('currencies');
$currencies->insert($this->dbDefaultValues['default_currency'])->saveData();
$result = $this->query('SELECT id FROM `currencies` WHERE `code` = "' . $this->dbDefaultValues['default_currency']['code'] . '"');

$data = $result->fetch(\PDO::FETCH_OBJ);

//single row save
$this->table('registry')
    ->insert(['reggroup' => 'ESHOP', 'regkey' => 'DEFAULT_CURRENCY', 'regval' => $data->id, 'lang' => ''])
    ->saveData();
    
//batch row save
$this->table('registry')
->insert([
    ['reggroup' => 'ESHOP', 'regkey' => 'TRANS_COST_LIMIT', 'regval' => $this->dbDefaultValues['trans_cost_limit'], 'lang' => ''],
    ['reggroup' => 'ESHOP', 'regkey' => 'MIN_ORDER_AMOUNT', 'regval' => $this->dbDefaultValues['min_order_amount'], 'lang' => ''],
])
->saveData();

To run the seeders run php migrator.php seed:run

Clients

Existing clients

Set in .env value for APP_DB_MIGRATION_TABLE Change in database/migrations/20240920143439_initial_schema.php and database/seeders/InitialSeed.php the return value from true to false in shouldExecute method Execute php migrator.php migrate to initialize migration table

New Clients

Set in .env value for APP_DB_MIGRATION_TABLE

if you do not want to open the Wizard with the settings open the migration method SetInitialWizardCompleted::shouldExecute to return true

If client needs new bridge tables migrations change in database/migrations/20240923141428_new_bridge_tables.php the return value from false to true in shouldExecute method.

Execute php migrator.php migrate to initialize migration table and run migrations.

Execute php migrator.php seed:run to initialize migration table and run migrations (This command will execute all seeders, for new clients that does not require fake data in their database,

you should run php migrator.php seed:run --seed=InitialSeed to run only initial seed)