-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some setup is required. 1. Add a file `src/secrets.ts` with the contents: ```ts export const user = '<your username>' export const password = '<your password>' ``` 2. Before running `yarn start` setup tunneling with: ``` ssh -L 5432:lkdb:5432 ab123456@students.mimuw.edu.pl ``` 3. Run `yarn start` If everything worked correctly, you should see two tables created under your account: `Games` and `Players`. Closes #4
- Loading branch information
Showing
14 changed files
with
715 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
dist/ | ||
node_modules/ | ||
coverage/ | ||
src/secrets.ts | ||
src/serviceAccount.json | ||
yarn-error.log | ||
yarn-error.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
yarn pretty | ||
yarn lint | ||
npx lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ package.json | |
tsconfig.json | ||
yarn.lock | ||
yarn-error.log | ||
coverage/ | ||
coverage/ | ||
src/secrets.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import pg from 'pg' | ||
import { user, password } from './secrets' | ||
// pq is a CommonJS module, so we have to do it this way for the import to work | ||
const { Client } = pg | ||
|
||
const client = new Client({ | ||
user, | ||
password, | ||
database: 'bd', | ||
port: 5432, | ||
host: 'localhost', | ||
}) | ||
|
||
export async function databaseInit(): Promise<void> { | ||
let success = true | ||
|
||
try { | ||
// Connect | ||
await client.connect() | ||
|
||
// Create the tables | ||
// This will fail if tables already exist, but we don't care | ||
try { | ||
await client.query( | ||
`CREATE TABLE IF NOT EXISTS Players ( | ||
id SERIAL UNIQUE NOT NULL, | ||
token VARCHAR(250) NOT NULL PRIMARY KEY, | ||
nickname VARCHAR(20) NOT NULL, | ||
turn BIGINT NOT NULL, | ||
game_id VARCHAR(6), | ||
card1 VARCHAR(3), | ||
card2 VARCHAR(3), | ||
funds BIGINT, | ||
bet BIGINT | ||
)` | ||
) | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
|
||
try { | ||
await client.query( | ||
`CREATE TABLE IF NOT EXISTS Games ( | ||
game_id VARCHAR(6) PRIMARY KEY, | ||
game_master SERIAL REFERENCES Players(id) NOT NULL, | ||
card1 VARCHAR(3), | ||
card2 VARCHAR(3), | ||
card3 VARCHAR(3), | ||
card4 VARCHAR(3), | ||
card5 VARCHAR(3), | ||
game_round BIGINT DEFAULT 0 NOT NULL, | ||
starting_funds BIGINT NOT NULL, | ||
small_blind BIGINT NOT NULL, | ||
small_blind_who SERIAL REFERENCES Players(id) NOT NULL, | ||
current_table_value BIGINT, | ||
current_player SERIAL REFERENCES Players(id) NOT NULL | ||
)` | ||
) | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
} catch (err) { | ||
console.error(err) | ||
success = false | ||
} finally { | ||
try { | ||
await client.end() | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
} | ||
|
||
if (success) { | ||
await Promise.resolve() | ||
} else { | ||
await Promise.reject(new Error('Failed to connect to database')) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.