Files
thetool/db/migrations/20251214150000_create_journal_table.php

35 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class CreateJournalTable extends AbstractMigration
{
public function up(): void
{
if ($this->getEnvironment() == "thetool") {
$this->table('Journal')
->addColumn('user_id', 'integer', ['null' => true, 'signed' => false])
->addColumn('model', 'string', ['limit' => 255, 'null' => false])
->addColumn('record_id', 'integer', ['null' => false])
->addColumn('action', 'enum', ['values' => ['create', 'update', 'delete'], 'null' => false])
->addColumn('field', 'string', ['limit' => 255, 'null' => true])
->addColumn('old_value', 'text', ['null' => true])
->addColumn('new_value', 'text', ['null' => true])
->addColumn('timestamp', 'timestamp', ['default' => 'CURRENT_TIMESTAMP'])
->addIndex(['model', 'record_id'], ['name' => 'idx_model_record'])
->addIndex(['user_id'], ['name' => 'idx_user'])
->addIndex(['action'], ['name' => 'idx_action'])
->addIndex(['timestamp'], ['name' => 'idx_timestamp'])
->create();
}
}
public function down(): void
{
if ($this->getEnvironment() == "thetool") {
$this->table('Journal')->drop()->save();
}
}
}