Changed database structure a bit; fixed code style problems in the old migrations

This commit is contained in:
Gregory Ballantine 2024-06-03 08:18:35 -04:00
parent 33c9bf5cb5
commit bd4c79a6fc
3 changed files with 52 additions and 54 deletions

View File

@ -5,31 +5,23 @@ use Phinx\Migration\AbstractMigration;
final class AddInitialTables extends AbstractMigration { final class AddInitialTables extends AbstractMigration {
public function change(): void { public function change(): void {
// hardware components // hardware components
$components_table = $this->table('components'); $components_table = $this->table('components');
$components_table->addColumn('name', 'string', ['null' => false]) $components_table->addColumn('name', 'string', ['null' => false])
->addColumn('type', 'string', ['null' => false]) ->addColumn('type', 'string', ['null' => false])
->addTimestamps() ->addTimestamps()
->addIndex(['name', 'type']) ->addIndex(['name', 'type'])
->create(); ->create();
// benchmarks // benchmarks
$benchmarks_table = $this->table('benchmarks'); $benchmarks_table = $this->table('benchmarks');
$benchmarks_table->addColumn('name', 'string', ['null' => false]) $benchmarks_table->addColumn('name', 'string', ['null' => false])
->addColumn('description', 'string') ->addColumn('description', 'string')
->addColumn('scoring', 'string', ['null' => false]) ->addColumn('scoring', 'string', ['null' => false])
->addTimestamps() ->addTimestamps()
->addIndex(['name', 'scoring']) ->addIndex(['name', 'scoring'])
->create(); ->create();
}
// benchmark test results
$table = $this->table('results');
$table->addColumn('average', 'integer', ['null' => false])
->addColumn('minimum', 'integer')
->addColumn('maximum', 'integer')
->addTimestamps()
->create();
}
} }

View File

@ -3,34 +3,16 @@ declare(strict_types=1);
use Phinx\Migration\AbstractMigration; use Phinx\Migration\AbstractMigration;
final class AddTestsTable extends AbstractMigration final class AddTestsTable extends AbstractMigration {
{
/** public function change(): void {
* Change Method. $table = $this->table('tests');
* $table->addColumn('title', 'string', ['null' => false])
* Write your reversible migrations using this method. ->addColumn('description', 'string')
* ->addColumn('component_id', 'integer', ['null' => false])
* More information on writing migrations is available here: ->addForeignKey('component_id', 'components', 'id', ['delete'=> 'CASCADE', 'update'=> 'CASCADE'])
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method ->addTimestamps()
* ->create();
* Remember to call "create()" or "update()" and NOT "save()" when working }
* with the Table class.
*/
public function change()
{
$table = $this->table('tests');
$table->addColumn('title', 'string', ['null' => false])
->addColumn('description', 'string')
->addColumn('benchmark_id', 'integer', ['null' => false])
->addColumn('component_id', 'integer', ['null' => false])
->addForeignKey('benchmark_id', 'benchmarks', 'id', ['delete'=> 'CASCADE', 'update'=> 'CASCADE'])
->addForeignKey('component_id', 'components', 'id', ['delete'=> 'CASCADE', 'update'=> 'CASCADE'])
->addTimestamps()
->create();
$results = $this->table('results');
$results->addColumn('test_id', 'integer', ['null' => false])
->addForeignKey('test_id', 'tests', 'id', ['delete'=> 'CASCADE', 'update'=> 'CASCADE'])
->update();
}
} }

View File

@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class AddResultsTable extends AbstractMigration {
public function change(): void {
// benchmark test results
$table = $this->table('results');
$table->addColumn('average', 'integer', ['null' => false])
->addColumn('minimum', 'integer')
->addColumn('maximum', 'integer')
->addColumn('test_id', 'integer', ['null' => false])
->addColumn('component_id', 'integer', ['null' => false])
->addColumn('benchmark_id', 'integer', ['null' => false])
->addForeignKey('test_id', 'tests', 'id', ['delete'=> 'CASCADE', 'update'=> 'CASCADE'])
->addForeignKey('component_id', 'components', 'id', ['delete'=> 'CASCADE', 'update'=> 'CASCADE'])
->addForeignKey('benchmark_id', 'benchmarks', 'id', ['delete'=> 'CASCADE', 'update'=> 'CASCADE'])
->addTimestamps()
->create();
}
}