marques-j-robinson / tic-tac-toe-api

1 stars 0 forks source link

DB Create Statements #1

Open marques-j-robinson opened 11 months ago

marques-j-robinson commented 11 months ago
CREATE DATABASE `tic_tac_toe` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;
USE `tic_tac_toe`;
CREATE TABLE `game` (
  `game_id` int NOT NULL AUTO_INCREMENT,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `name` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`game_id`)
) ENGINE=InnoDB AUTO_INCREMENT=38 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE `history` (
  `game_id` int NOT NULL,
  `move_id` int NOT NULL,
  `board_id` int NOT NULL,
  `value` varchar(45) NOT NULL,
  PRIMARY KEY (`game_id`,`move_id`,`board_id`,`value`),
  UNIQUE KEY `unique_move_idx` (`game_id`,`move_id`,`board_id`,`value`),
  KEY `fk_game_history_idx` (`game_id`),
  CONSTRAINT `fk_game_history` FOREIGN KEY (`game_id`) REFERENCES `game` (`game_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
mantisg commented 10 months ago

This now runs perfectly. It creates the db and tables as intended. Whatever changes you made to the api allowed workbench to recognize all the syntax used here.

marques-j-robinson commented 10 months ago

@mantisg perfect! Still have some updates for this so be on the lookout in the next few days for an update to this. I'll ping you when it's ready so you'll need to copy whatever is here again. I'm reworking the db structure pretty rigorously finding the right storage pattern for the tic tac toe app.

marques-j-robinson commented 10 months ago

@mantisg the issue was one of the comment characters were not being displayed causing it to spit out a syntax error.

mantisg commented 10 months ago

@marques-j-robinson I'll be watching like a hawk for that update, sir. Of course, it was something small like that. It always is. Awesome that you found it and it works now. If the db is being restructured, won't the user need to delete the current db and re-copy the create statements to make a new db or will there be a set of queries to append the new structure to the existing db? Something to think about when having new users just copy and paste commands they may not fully understand. Not just myself, but others using your instructions to expand the React tutorial.

marques-j-robinson commented 10 months ago

@mantisg by the time the tutorial is written the db schema will be solidified so no need to worry. It's normal when architecting to drop a whole schema in favor of an alternate one so just drop the whole schema and copy/pasta the new one when it is ready.

mantisg commented 10 months ago

@marques-j-robinson Cool cool, that works for me. Pretty sure I'm the only one who is testing this stuff and navigating it before it's done anyway.

marques-j-robinson commented 10 months ago

@mantisg The issue has been updated