Permalink
Browse files

Micah - updated make setup to create databases and config files for b…

…oth postgres and mysql.
  • Loading branch information...
1 parent 4b74fe8 commit 6141eb6f7bd4394955b1aad2ca21fe6002373343 Micah Silverman committed Oct 27, 2012
Showing with 84 additions and 5 deletions.
  1. +2 −1 .gitignore
  2. +2 −1 Makefile
  3. +1 −0 package.json
  4. +76 −0 test/bootstrap/init_mysql.js
  5. +3 −3 test/bootstrap/{init.js → init_pg.js}
View
@@ -1,3 +1,4 @@
.DS_Store
-.fastlegs
+.fastlegs_pg
+.fastlegs_mysql
node_modules
View
@@ -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 \
View
@@ -8,6 +8,7 @@
"dependencies": {
"async": "0.1.18",
"pg": "0.6.18",
+ "mysql": "2.0.0-alpha3",
"underscore": "1.3.3"
},
"devDependencies": {
@@ -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() }
+ }
+ )
+})
@@ -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(); }
}
);
}

0 comments on commit 6141eb6

Please sign in to comment.