diff --git a/backend/db/blueprint.sql b/backend/db/blueprint.sql new file mode 100644 index 0000000..d74b773 --- /dev/null +++ b/backend/db/blueprint.sql @@ -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; \ No newline at end of file diff --git a/backend/db/migrations/20260730124014_create_stores_table.php b/backend/db/migrations/20260730124014_create_stores_table.php new file mode 100644 index 0000000..8c7247f --- /dev/null +++ b/backend/db/migrations/20260730124014_create_stores_table.php @@ -0,0 +1,30 @@ +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(); + } +} diff --git a/backend/db/migrations/20260730124217_create_employees_table.php b/backend/db/migrations/20260730124217_create_employees_table.php new file mode 100644 index 0000000..6169bec --- /dev/null +++ b/backend/db/migrations/20260730124217_create_employees_table.php @@ -0,0 +1,28 @@ +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(); + } +} diff --git a/backend/db/migrations/20260730124354_create_customers_table.php b/backend/db/migrations/20260730124354_create_customers_table.php new file mode 100644 index 0000000..4745538 --- /dev/null +++ b/backend/db/migrations/20260730124354_create_customers_table.php @@ -0,0 +1,29 @@ +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(); + } +} diff --git a/backend/db/migrations/20260730124432_create_histories_table.php b/backend/db/migrations/20260730124432_create_histories_table.php new file mode 100644 index 0000000..bcb5ed4 --- /dev/null +++ b/backend/db/migrations/20260730124432_create_histories_table.php @@ -0,0 +1,33 @@ +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(); + } +}