Skip to content

Commit

Permalink
Micah - updated make setup to create databases and config files for b…
Browse files Browse the repository at this point in the history
…oth postgres and mysql.
  • Loading branch information
Micah Silverman committed Oct 27, 2012
1 parent 4b74fe8 commit 6141eb6
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,3 +1,4 @@
.DS_Store
.fastlegs
.fastlegs_pg
.fastlegs_mysql
node_modules
3 changes: 2 additions & 1 deletion Makefile
Expand Up @@ -8,7 +8,8 @@ integration_files=`find test/integration -name '$(file)' -type f -print0 | xargs
test: setup test-unit test-integration

setup:
@[ -e ".fastlegs" ] || node test/bootstrap/init.js
@[ -e ".fastlegs_pg" ] || node test/bootstrap/init_pg.js
@[ -e ".fastlegs_mysql" ] || node test/bootstrap/init_mysql.js

test-unit:
@NODE_ENV=test ./node_modules/.bin/mocha \
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -8,6 +8,7 @@
"dependencies": {
"async": "0.1.18",
"pg": "0.6.18",
"mysql": "2.0.0-alpha3",
"underscore": "1.3.3"
},
"devDependencies": {
Expand Down
76 changes: 76 additions & 0 deletions test/bootstrap/init_mysql.js
@@ -0,0 +1,76 @@
var fs = require('fs')
, async = require("async")
, mysql = require("mysql")
, read = require('read')

var create = {
"posts":
"CREATE TABLE posts (\
id integer NOT NULL,\
title character varying(255) NOT NULL,\
blurb character varying(255),\
body text NOT NULL,\
published boolean,\
created_at date,\
updated_at date,\
CONSTRAINT posts_pkey PRIMARY KEY (id))",
"comments":
"CREATE TABLE comments (\
id integer NOT NULL,\
post_id integer NOT NULL,\
comment text NOT NULL,\
created_at date,\
CONSTRAINT comments_pkey PRIMARY KEY (id))",
"comments_post_id_index":
"CREATE INDEX comments_post_id \
ON comments (post_id) \
USING BTREE"
}

console.log("\nFastLegS - Please enter your MySQL credentials " +
"and a database for us to create.\nNOTE: Make sure you specify " +
"a database that does not already exist.\n")

async.series({
"username": function(cb) {
read({prompt: "mysql username: "}, cb);
},
"password": function(cb) {
read({ prompt: "mysql password: ", silent: true }, cb)
},
"database": function(cb) {
read({ prompt: "mysql database: ", default: "fastlegs_test" }, cb)
},
"host": function(cb) {
read({ prompt: "mysql host: ", default: "localhost" }, cb)
},
"port": function(cb) {
read({ prompt: "mysql port: ", default: 3306 }, cb)
},
}, function(err, config) {
var connectionString = "mysql://" + config.username +
((config.password)?(":" + config.password):"") +
"@" + config.host + ":" + config.port + "/";
var connection = mysql.createConnection(connectionString)
connection.query( "CREATE DATABASE " + config.database,
function(err, result) {
if (!err) {
connection.end()
connection = mysql.createConnection(connectionString + config.database)
async.series([
function(cb) { connection.query(create.posts, cb); },
function(cb) { connection.query(create.comments, cb); },
function(cb) { connection.query(create.comments_post_id_index, cb); }
], function(err, results) {
if (!err) {
fs.writeFile('.fastlegs_mysql',
JSON.stringify(config),
function (err) {
process.exit();
});
} else { console.dir(err); connection.end() }
});
} else { console.dir(err); connection.end() }
}
)
})
6 changes: 3 additions & 3 deletions test/bootstrap/init.js → test/bootstrap/init_pg.js
Expand Up @@ -67,17 +67,17 @@ async.series({
function(cb) { client.query(create.comments_post_id_index, cb); }
], function(err, results) {
if (!err) {
fs.writeFile('.fastlegs',
fs.writeFile('.fastlegs_pg',
JSON.stringify(config),
function (err) {
client.end();
process.exit();
});
} else { client.end(); }
} else { console.dir(err); client.end(); }
});
}
});
} else { client.end(); }
} else { console.dir(err); client.end(); }
}
);
}
Expand Down

0 comments on commit 6141eb6

Please sign in to comment.