Skip to content

Commit

Permalink
Merge branch 'ahockersten/own_database' of https://github.com/ahocker…
Browse files Browse the repository at this point in the history
…sten/yasp into ahockersten-ahockersten/own_database

Conflicts:
	package.json
	sql/create_tables.sql
  • Loading branch information
albertcui committed Oct 31, 2015
2 parents 53e4567 + 41c21c7 commit 905d2a4
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 29 deletions.
2 changes: 1 addition & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var defaults = {
"PARSER_PORT": "5200",
"PROXY_PORT": "5300",
"WORK_PORT": "5400",
"POSTGRES_URL": "postgresql://postgres:postgres@localhost/postgres",
"POSTGRES_URL": "postgresql://yasp:yasp@localhost/yasp",
"REDIS_URL": "redis://127.0.0.1:6379/0",
"RETRIEVER_HOST": "localhost:5100",
"PARSER_HOST": "localhost:5200",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"maven": "mvn -q -f java_parser/pom.xml clean install -U",
"build": "npm install && npm run maven && npm run webpack",
"startup": "sudo pm2 startup ubuntu -u yasp",
"create": "sudo -u postgres psql -f sql/create.sql",
"create": "bash sql/create.sh",
"deploy-core": "git pull origin master && npm run build && node deploy core",
"deploy-parser": "git pull origin master && npm run build && node deploy parser"
"deploy-parser": "git pull origin master && npm run maven && node deploy parser"
},
"repository": {
"type": "git",
Expand Down
7 changes: 7 additions & 0 deletions sql/create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
sudo -u postgres dropdb yasp
sudo -u postgres dropuser yasp
sudo -u postgres createuser yasp
sudo -u postgres psql -c "ALTER USER yasp WITH PASSWORD 'yasp';"
sudo -u postgres createdb yasp --owner yasp
cat sql/create_tables.sql | sudo -u postgres psql -d postgresql://yasp:yasp@localhost/yasp -f -
8 changes: 2 additions & 6 deletions sql/create.sql → sql/create_tables.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
--default schema is public
drop schema public cascade;
create schema public;

CREATE TABLE matches (
match_id bigint PRIMARY KEY,
match_seq_num bigint,
Expand Down Expand Up @@ -143,7 +139,7 @@ CREATE TABLE player_ratings (
account_id bigint REFERENCES players(account_id) ON DELETE CASCADE,
match_id bigint,
solo_competitive_rank integer,
competitive_rank integer,
competitive_rank integer,
time timestamp with time zone
);

Expand All @@ -152,4 +148,4 @@ CREATE INDEX on matches(version);
CREATE INDEX on players(full_history_time);
CREATE INDEX on players(last_login);
CREATE INDEX on players(cheese);
CREATE INDEX on player_ratings(account_id, time);
CREATE INDEX on player_ratings(account_id, time);
66 changes: 46 additions & 20 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var config = require('../config');
config.PORT = ""; //use service defaults
config.MONGO_URL = "mongodb://localhost/test";
config.POSTGRES_URL = "postgres://postgres:postgres@localhost/template1";
config.POSTGRES_URL = "postgres://yasp_test:yasp_test@localhost/yasp_test";
config.REDIS_URL = "redis://localhost:6379/1";
config.SESSION_SECRET = "testsecretvalue";
config.NODE_ENV = "test";
Expand All @@ -27,11 +27,10 @@ var replay_dir = "./testfiles/";
var pg = require('pg');
var fs = require('fs');
var wait = 90000;
var db = require('../db');
var app = require('../web');
var queries = require('../queries');
var insertMatch = queries.insertMatch;
var insertPlayer = queries.insertPlayer;
// these are loaded later, as the database needs to be created when these are required
var db;
var app;
var queries;
//nock.disableNetConnect();
//nock.enableNetConnect();
//fake api response
Expand Down Expand Up @@ -61,22 +60,46 @@ before(function(done) {
this.timeout(wait);
async.series([
function(cb) {
console.log('connecting to pg');
console.log('removing old test database');
pg.connect("postgres://postgres:postgres@localhost/postgres", function(err, client) {
if (err) {
return cb(err);
}
client.query('DROP ROLE IF EXISTS yasp_test;', function(err, result) {
console.log('cleaning database role for testing');
});
client.query('DROP DATABASE IF EXISTS yasp_test;', function(err, result) {
console.log('cleaning test database', config.POSTGRES_URL);
cb(err);
});
});
},
function(cb) {
console.log('creating test database');
pg.connect("postgres://postgres:postgres@localhost/postgres", function(err, client) {
if (err) {
return cb(err);
}
client.query('CREATE ROLE yasp_test WITH LOGIN PASSWORD \'yasp_test\';', function(err, result) {
console.log('creation of database role for testing');
});
client.query('CREATE DATABASE yasp_test OWNER yasp_test;', function(err, result) {
console.log('creation of test database', config.POSTGRES_URL);
cb(err);
});
});
},
function(cb) {
console.log('connecting to test database and creating tables');
pg.connect(config.POSTGRES_URL, function(err, client) {
if (err) {
return cb(err);
}
console.log('cleaning db');
//clean the db
client.query('drop schema public cascade;create schema public;', function() {
//databaseCleaner.clean(client, function() {
console.log('cleaned %s', config.POSTGRES_URL);
//set up db
var query = fs.readFileSync("./sql/create.sql", "utf8");
client.query(query, function(err, result) {
console.log('set up %s', config.POSTGRES_URL);
cb(err);
});
// create tables
var query = fs.readFileSync("./sql/create_tables.sql", "utf8");
client.query(query, function(err, result) {
console.log('set up %s', config.POSTGRES_URL);
cb(err);
});
});
},
Expand All @@ -85,17 +108,20 @@ before(function(done) {
redis.flushdb(cb);
},
function(cb) {
db = require('../db');
app = require('../web');
queries = require('../queries');
console.log("loading matches");
async.mapSeries([require('./details_api.json').result], function(m, cb) {
insertMatch(db, redis, queue, m, {
queries.insertMatch(db, redis, queue, m, {
type: "api"
}, cb);
}, cb);
},
function(cb) {
console.log("loading players");
async.mapSeries(require('./summaries_api').response.players, function(p, cb) {
insertPlayer(db, p, cb);
queries.insertPlayer(db, p, cb);
}, cb);
}], function(err) {
require('../workServer');
Expand Down

0 comments on commit 905d2a4

Please sign in to comment.