Feat: db migrations [WIP]
This commit is contained in:
		
							
								
								
									
										6
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								Makefile
									
									
									
									
									
								
							| @@ -33,3 +33,9 @@ stop-container: | ||||
|  | ||||
| run-container: stop-container | ||||
| 	docker run --name=gralias -v $(CURDIR)/store.json:/root/store.json -p 0.0.0.0:3000:3000 -d gralias:master | ||||
|  | ||||
| migrate-up: | ||||
| 	migrate -database 'sqlite3://gralias.db' -path migrations up | ||||
|  | ||||
| migrate-down: | ||||
| 	migrate -database 'sqlite3://gralias.db' -path migrations down | ||||
|   | ||||
							
								
								
									
										
											BIN
										
									
								
								gralias.db
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								gralias.db
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										7
									
								
								migrations/001_initial_schema.down.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								migrations/001_initial_schema.down.sql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | ||||
| -- migrations/001_initial_schema.down.sql | ||||
|  | ||||
| DROP TABLE IF EXISTS actions; | ||||
| DROP TABLE IF EXISTS card_marks; | ||||
| DROP TABLE IF EXISTS word_cards; | ||||
| DROP TABLE IF EXISTS players; | ||||
| DROP TABLE IF EXISTS rooms; | ||||
							
								
								
									
										62
									
								
								migrations/001_initial_schema.up.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								migrations/001_initial_schema.up.sql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,62 @@ | ||||
| -- migrations/001_initial_schema.up.sql | ||||
|  | ||||
| CREATE TABLE rooms ( | ||||
|     id TEXT PRIMARY KEY, | ||||
|     created_at TIMESTAMP NOT NULL, | ||||
|     creator_name TEXT NOT NULL, | ||||
|     team_turn TEXT, | ||||
|     this_turn_limit INTEGER, | ||||
|     opened_this_turn INTEGER, | ||||
|     blue_counter INTEGER, | ||||
|     red_counter INTEGER, | ||||
|     red_turn BOOLEAN, | ||||
|     mime_done BOOLEAN, | ||||
|     is_public BOOLEAN, | ||||
|     is_running BOOLEAN, | ||||
|     language TEXT, | ||||
|     round_time INTEGER, | ||||
|     is_over BOOLEAN, | ||||
|     team_won TEXT, | ||||
|     room_pass TEXT | ||||
| ); | ||||
|  | ||||
| CREATE TABLE players ( | ||||
|     id INTEGER PRIMARY KEY AUTOINCREMENT, | ||||
|     room_id TEXT NOT NULL, | ||||
|     username TEXT NOT NULL, | ||||
|     team TEXT, -- 'red' or 'blue' | ||||
|     role TEXT, -- 'guesser' or 'mime' | ||||
|     is_bot BOOLEAN DEFAULT FALSE, | ||||
|     FOREIGN KEY (room_id) REFERENCES rooms(id) | ||||
| ); | ||||
|  | ||||
| CREATE TABLE word_cards ( | ||||
|     id INTEGER PRIMARY KEY AUTOINCREMENT, | ||||
|     room_id TEXT NOT NULL, | ||||
|     word TEXT NOT NULL, | ||||
|     color TEXT, | ||||
|     revealed BOOLEAN DEFAULT FALSE, | ||||
|     mime_view BOOLEAN DEFAULT FALSE, | ||||
|     FOREIGN KEY (room_id) REFERENCES rooms(id) | ||||
| ); | ||||
|  | ||||
| CREATE TABLE card_marks ( | ||||
|     id INTEGER PRIMARY KEY AUTOINCREMENT, | ||||
|     card_id INTEGER NOT NULL, | ||||
|     username TEXT NOT NULL, | ||||
|     active BOOLEAN DEFAULT TRUE, | ||||
|     FOREIGN KEY (card_id) REFERENCES word_cards(id) | ||||
| ); | ||||
|  | ||||
| CREATE TABLE actions ( | ||||
|     id INTEGER PRIMARY KEY AUTOINCREMENT, | ||||
|     room_id TEXT NOT NULL, | ||||
|     actor TEXT NOT NULL, | ||||
|     actor_color TEXT, | ||||
|     action_type TEXT NOT NULL, | ||||
|     word TEXT, | ||||
|     word_color TEXT, | ||||
|     number_associated TEXT, -- for clues | ||||
|     created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||||
|     FOREIGN KEY (room_id) REFERENCES rooms(id) | ||||
| ); | ||||
							
								
								
									
										9
									
								
								repos/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								repos/main.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| package repos | ||||
|  | ||||
| type AllRepos interface { | ||||
| 	RoomsRepo | ||||
| } | ||||
|  | ||||
| type RepoProvider struct { | ||||
| 	// db connection | ||||
| } | ||||
							
								
								
									
										15
									
								
								repos/rooms.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								repos/rooms.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | ||||
| package repos | ||||
|  | ||||
| import "gralias/models" | ||||
|  | ||||
| type RoomsRepo interface { | ||||
| 	ListRooms() ([]models.Room, error) | ||||
| 	GetRoomByID(id string) (*models.Room, error) | ||||
| 	CreateRoom(room *models.Room) error | ||||
| 	DeleteRoomByID(id string) error | ||||
| } | ||||
|  | ||||
| // provider implementation | ||||
| func (p RepoProvider) ListRooms() ([]models.Room, error) { | ||||
| 	return nil, nil | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder