Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions backend/db/blueprint.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
CREATE TABLE IF NOT EXISTS `stores` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`parent_id` INT DEFAULT NULL,
`name` VARCHAR(255) NOT NULL,
FOREIGN KEY (`parent_id`) REFERENCES `stores`(`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `employees` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`store_id` INT NOT NULL,
`name` VARCHAR(255) NOT NULL,
FOREIGN KEY (`store_id`) REFERENCES `stores`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `customers` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`user_id` BIGINT NOT NULL,
`paid` BOOLEAN NOT NULL DEFAULT FALSE,
`disabled` BOOLEAN NOT NULL DEFAULT FALSE, -- ゲーム終了時 true
UNIQUE KEY `uk_user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `histories` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`customer_user_id` BIGINT NOT NULL,
`store_id` INT NOT NULL,
`score` INT NOT NULL,
`time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (`customer_user_id`) REFERENCES `customers`(`user_id`) ON DELETE NO ACTION,
FOREIGN KEY (`store_id`) REFERENCES `stores`(`id`) ON DELETE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
30 changes: 30 additions & 0 deletions backend/db/migrations/20260730124014_create_stores_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateStoresTable 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('stores');
$table->addColumn('parent_id', 'integer', ['null' => true, 'default' => null, 'signed'=> false])
->addColumn('name', 'string', ['limit' => 255, 'null' => false])
->create();

$table->addForeignKey('parent_id', 'stores', 'id', ['delete' => 'SET_NULL', 'update' => 'NO_ACTION'])
->update();
}
}
28 changes: 28 additions & 0 deletions backend/db/migrations/20260730124217_create_employees_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateEmployeesTable 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('employees');
$table->addColumn('store_id', 'integer', ['null' => false, 'signed'=>false]) // integerに変更
->addColumn('name', 'string', ['limit' => 255, 'null' => false])
->addForeignKey('store_id', 'stores', 'id', ['delete' => 'CASCADE', 'update' => 'NO_ACTION'])
->create();
}
}
29 changes: 29 additions & 0 deletions backend/db/migrations/20260730124354_create_customers_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateCustomersTable 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('customers');
$table->addColumn('user_id', 'biginteger', ['null' => false])
->addColumn('paid', 'boolean', ['null' => false, 'default' => false])
->addColumn('disabled', 'boolean', ['null' => false, 'default' => false])
->addIndex(['user_id'], ['unique' => true])
->create();
}
}
33 changes: 33 additions & 0 deletions backend/db/migrations/20260730124432_create_histories_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateHistoriesTable 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('histories');
$table->addColumn('customer_user_id', 'biginteger', ['null' => false])
->addColumn('store_id', 'integer', ['null' => false, 'signed'=>false])
->addColumn('score', 'integer', ['null' => false])
->addColumn('time', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])
->addForeignKey('customer_user_id', 'customers', 'user_id', ['delete' => 'NO_ACTION', 'update' => 'NO_ACTION'])
->addForeignKey('store_id', 'stores', 'id', ['delete' => 'NO_ACTION', 'update' => 'NO_ACTION'])
->addIndex(['customer_user_id', 'time'])
->addIndex(['store_id', 'time'])
->create();
}
}
Loading