SiteWeaver_CMS/database/migrations/20260906021600_plugins.php

50 lines
2 KiB
PHP
Raw Normal View History

<?php
/**
* 20260906021600_plugins.php
*
* Author: Funky Waddle
* Date: 2026-09-06
*
* Purpose: Migration that creates the `plugins` table storing installed plugin records.
*/
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class Plugins extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change(): void
{
$table = $this->table('plugins');
$table->addColumn('name', 'string', ['limit' => 255, 'null'=> false])
->addColumn('version', 'string', ['limit' => 10, 'null' => false])
->addColumn('core_version', 'string', ['limit' => 10, 'null' => false])
// Plain string (not Phinx's 'enum' type) - Phinx's SQLite adapter does not
// support the 'enum' column type at all, and this project must support
// SQLite3/MySQL/MariaDB/PostgreSQL uniformly (see `tech_stack.database` in
// APP.yaml). Allowed values ('Active', 'Deactivated', 'Error') are validated
// in the application layer (see `SiteWeaver\Plugin\PluginModel`).
->addColumn('status', 'string', ['limit' => 20, 'null' => false, 'default' => 'Deactivated'])
->addColumn('created_at', 'datetime', ['null' => false, 'default'=>"CURRENT_TIMESTAMP"])
->addColumn('created_by', 'integer', ['null' => false])
->addColumn('updated_at', 'datetime', ['null' => true])
->addColumn('updated_by', 'integer', ['null' => true])
->addForeignKey('created_by', 'users','id')
->addForeignKey('updated_by', 'users','id')
->create();
}
}