-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpg_setup_with_clear.js
More file actions
24 lines (18 loc) · 1.19 KB
/
pg_setup_with_clear.js
File metadata and controls
24 lines (18 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
var pg = require('pg').native,
connectionString = process.env.DATABASE_URL || "tcp://postgres:123@localhost/gmnct",
client, query;
console.log("connecting to: " + connectionString);
client = new pg.Client(connectionString);
client.connect();
client.query('DROP TABLE IF EXISTS lobbies');
client.query('DROP TABLE IF EXISTS games');
client.query('DROP TABLE IF EXISTS users');
client.query('DROP TABLE IF EXISTS lobby_userlist');
client.query('CREATE TABLE users (id SERIAL PRIMARY KEY, username varchar(64) UNIQUE, email varchar(255) UNIQUE, password varchar(255), registration_opt_in boolean DEFAULT false)');
client.query('CREATE TABLE games (id SERIAL PRIMARY KEY, name varchar(128) UNIQUE, category varchar(255) )');
client.query('CREATE TABLE lobbies (id SERIAL PRIMARY KEY, name varchar(128) UNIQUE, owner integer REFERENCES users(id), game integer REFERENCES games(id) )');
client.query('CREATE TABLE lobby_userlist (lobby_id integer REFERENCES lobbies(id), user_id integer REFERENCES users(id) )');
var query = client.query("INSERT INTO games(name, category) VALUES ('World of Warcraft', 'MMORPG'), ('CS:GO', 'FPS'), ('Command&Conquer', 'RTS')");
query.on("end", function(){
client.end();
});