Skip to content

Commit

Permalink
remove postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew4699 committed Apr 11, 2021
1 parent b0faa69 commit 30e9cc3
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 121 deletions.
16 changes: 2 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: start stop restart up-server up-web up-postgres ssh logs
.PHONY: start stop restart up-server up-web ssh logs

# Start all services
start: | up-web up-server up-postgres
start: | up-web up-server

# Kill all services
stop:
Expand All @@ -18,10 +18,6 @@ up-server:
up-web:
@docker-compose up -d web

# Start the postgres container
up-postgres:
@docker-compose up -d postgres

# Clears the build cache and rebuilds the container
build-server-fresh:
@docker-compose build --no-cache server
Expand All @@ -30,10 +26,6 @@ build-server-fresh:
build-web-fresh:
@docker-compose build --no-cache web

# Clears the build cache and rebuilds the container
build-postgres-fresh:
@docker-compose build --no-cache postgres

# SSH into a container
# EXAMPLE: make ssh tar=web
ssh:
Expand All @@ -49,7 +41,3 @@ logs:
# Same as "logs" but with timestamps
logst:
@docker logs -t -f deuces-$${tar} --tail ${tail}

# Enter Postgres console
psql:
@docker exec -it deuces-postgres psql -U deuces_dev deuces
18 changes: 0 additions & 18 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,10 @@ services:
container_name: deuces-server
build: ./server
network_mode: "host"
depends_on:
- postgres
volumes:
- "./server:/opt/server/"
ports:
- "3012:3012"
environment:
POSTGRES_HOST: localhost
POSTGRES_USER: deuces_dev
POSTGRES_PASSWORD: deuces_dev
POSTGRES_DB: deuces

# Frontend website
web:
Expand All @@ -33,14 +26,3 @@ services:
- "3000:3000"
environment:
- TBD=for_later

postgres:
image: postgres:10.4
container_name: deuces-postgres
network_mode: "host"
ports:
- "5432:5432"
environment:
POSTGRES_USER: deuces_dev
POSTGRES_PASSWORD: deuces_dev
POSTGRES_DB: deuces
12 changes: 0 additions & 12 deletions server/db.js

This file was deleted.

17 changes: 0 additions & 17 deletions server/deuces.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,23 +291,6 @@ class Deuces {
setPlayerName(playerIdx, name) {
this.players[playerIdx].name = name;
}

load(data) {
Object.assign(this, data);
this.players = this.players.map(Player.deserialize);
}

serialize() {
const data = Object.assign(
{},
this,
{ players: this.players.map(player => player.serialize()) },
);

// delete data.emitter;
data.emitter = undefined;
return data;
}
}

module.exports = Deuces;
31 changes: 0 additions & 31 deletions server/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class Game {
}

onUpdate() {
this.saveToDB();
this.updateAllClients();
}

Expand All @@ -83,36 +82,6 @@ class Game {
client.emit('game_update', this.deuces.getGameStateForPlayer(client.player));
});
}

loadFromDBRecord(record) {
this.deuces = Deuces.fromDBRecord(record.deuces);
}

async createDBRecord() {
await db.games.insert({
id: this.id,
numplayers: this.numPlayers,
});

this.saveToDB();
}

saveToDB() {
return db.games.update({
id: this.id,
}, {
active: !this.deuces.hasWinner(),
deuces: this.deuces,
});
}

static fromDBRecord(record) {
const { id, numplayers } = record;

const game = new Game(id, numplayers);
game.deuces.load(record.deuces);
return game;
}
}

module.exports = Game;
1 change: 0 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"deasync": "^0.1.15",
"dotenv": "^8.0.0",
"express": "^4.17.1",
"massive": "^5.11.2",
"pokersolver": "^2.1.3",
"shortid": "^2.2.14",
"socket.io": "^2.2.0"
Expand Down
28 changes: 0 additions & 28 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');

const theDbToConnect = require('./db');
const Game = require('./game');
const loudSocket = require('./loud_socket');
const shortid = require('shortid');
Expand All @@ -13,21 +12,6 @@ const games = new Map();
const port = 3012;

(async function main() {
global.db = await theDbToConnect;

if(typeof db.games === 'undefined') {
await db.query(`CREATE TABLE IF NOT EXISTS games(
id VARCHAR(100) PRIMARY KEY,
numPlayers INTEGER,
active BOOLEAN,
deuces jsonb
)`);

global.db = await db.reload();
}

recoverGames(db);

// Listen for clients
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
Expand Down Expand Up @@ -64,7 +48,6 @@ function createGame(numPlayers) {
}

const game = new Game(id, numPlayers, createSimilarGame);
game.createDBRecord();
games.set(id, game);
return id;
}
Expand All @@ -91,14 +74,3 @@ function routeToGame(socket) {

game.onClientConnect(socket);
}

async function recoverGames(db) {
const activeGames = await db.games.find({ active: true });
activeGames.forEach(recoverGame);
}

function recoverGame(gameRecord) {
// console.log('recoverGame', gameRecord);
const game = Game.fromDBRecord(gameRecord);
games.set(game.id, game);
}

0 comments on commit 30e9cc3

Please sign in to comment.