From bd4c79a6fc1a48724d30cc3fdbe3822d50b552b7 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Mon, 3 Jun 2024 08:18:35 -0400 Subject: [PATCH] Changed database structure a bit; fixed code style problems in the old migrations --- .../20230921024609_add_initial_tables.php | 42 ++++++++----------- .../20230923020649_add_tests_table.php | 40 +++++------------- .../20240603081359_add_results_table.php | 24 +++++++++++ 3 files changed, 52 insertions(+), 54 deletions(-) create mode 100644 db/migrations/20240603081359_add_results_table.php diff --git a/db/migrations/20230921024609_add_initial_tables.php b/db/migrations/20230921024609_add_initial_tables.php index f5474e8..33f264f 100644 --- a/db/migrations/20230921024609_add_initial_tables.php +++ b/db/migrations/20230921024609_add_initial_tables.php @@ -5,31 +5,23 @@ use Phinx\Migration\AbstractMigration; final class AddInitialTables extends AbstractMigration { - public function change(): void { - // hardware components - $components_table = $this->table('components'); - $components_table->addColumn('name', 'string', ['null' => false]) - ->addColumn('type', 'string', ['null' => false]) - ->addTimestamps() - ->addIndex(['name', 'type']) - ->create(); + public function change(): void { + // hardware components + $components_table = $this->table('components'); + $components_table->addColumn('name', 'string', ['null' => false]) + ->addColumn('type', 'string', ['null' => false]) + ->addTimestamps() + ->addIndex(['name', 'type']) + ->create(); - // benchmarks - $benchmarks_table = $this->table('benchmarks'); - $benchmarks_table->addColumn('name', 'string', ['null' => false]) - ->addColumn('description', 'string') - ->addColumn('scoring', 'string', ['null' => false]) - ->addTimestamps() - ->addIndex(['name', 'scoring']) - ->create(); - - // benchmark test results - $table = $this->table('results'); - $table->addColumn('average', 'integer', ['null' => false]) - ->addColumn('minimum', 'integer') - ->addColumn('maximum', 'integer') - ->addTimestamps() - ->create(); - } + // benchmarks + $benchmarks_table = $this->table('benchmarks'); + $benchmarks_table->addColumn('name', 'string', ['null' => false]) + ->addColumn('description', 'string') + ->addColumn('scoring', 'string', ['null' => false]) + ->addTimestamps() + ->addIndex(['name', 'scoring']) + ->create(); + } } diff --git a/db/migrations/20230923020649_add_tests_table.php b/db/migrations/20230923020649_add_tests_table.php index 907fb45..03a947c 100644 --- a/db/migrations/20230923020649_add_tests_table.php +++ b/db/migrations/20230923020649_add_tests_table.php @@ -3,34 +3,16 @@ declare(strict_types=1); use Phinx\Migration\AbstractMigration; -final class AddTestsTable 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() - { - $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(); +final class AddTestsTable extends AbstractMigration { + + public function change(): void { + $table = $this->table('tests'); + $table->addColumn('title', 'string', ['null' => false]) + ->addColumn('description', 'string') + ->addColumn('component_id', 'integer', ['null' => false]) + ->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(); - } } diff --git a/db/migrations/20240603081359_add_results_table.php b/db/migrations/20240603081359_add_results_table.php new file mode 100644 index 0000000..efc51c0 --- /dev/null +++ b/db/migrations/20240603081359_add_results_table.php @@ -0,0 +1,24 @@ +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(); + } + +}