Created
January 27, 2011 19:00
-
-
Save pagameba/798996 to your computer and use it in GitHub Desktop.
testcase for long-stack-traces
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
{ | |
"version": "v0.3.1", | |
"web": { | |
"port": 8081 | |
}, | |
"database": { | |
"connection": "pg://postgres:[email protected]:5432/test" | |
} | |
} |
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
require('long-stack-traces'); | |
var Seq = require('seq'), | |
path = require('path'), | |
fs = require('fs'), | |
pg = require('pg'), | |
configFile = path.join(__dirname, '/config.json'); | |
Seq().seq(function() { | |
fs.readFile(configFile, this); | |
}) | |
.seq(function(data) { | |
global.config = JSON.parse(data); | |
if (config.database.connection) { | |
pg.connect(config.database.connection, this); | |
} | |
}) | |
.seq(function(client) { | |
console.log('connected to database'); | |
global.config.database.client = client; | |
fs.readdir(path.join(__dirname, 'sql'), this); | |
}) | |
.flatten() | |
.parEach(function(file) { | |
var that = this, | |
table = path.basename(file, '.sql'), | |
sql = "SELECT relname FROM pg_class WHERE relname = '"+table+"';"; | |
if (path.extname(file) == '.sql') { | |
console.log('checking for ' + table + ' with sql ' + sql); | |
global.config.database.client.query(sql, function(err, result) { | |
if (err) { | |
that(err); | |
} else if (result.rows.length == 0) { | |
console.log('loading sql for table'); | |
fs.readFile(path.join(__dirname, 'sql', file), function(err, data) { | |
if (err) { | |
that(err); | |
} else { | |
global.config.database.client.query(data.toString(), function(err, result) { | |
console.log('Table created, moving on'); | |
console.dir(err); | |
// at this point either it worked (and err is null) or it didn't and err | |
// should tell us why | |
that(err); | |
}); | |
} | |
}); | |
} else { | |
// table exists, carry on | |
that(); | |
} | |
}); | |
} | |
}) | |
.seq(function() { | |
console.log('okay, we are done here.'); | |
}) | |
.catch(function(err) { | |
console.error(err.stack ? err.stack : err); | |
}); |
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
CREATE TABLE test | |
( | |
testid serial NOT NULL | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment