diff --git a/.gitignore b/.gitignore index 71dfc0f..a847035 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store -.fastlegs +.fastlegs_pg +.fastlegs_mysql node_modules diff --git a/Makefile b/Makefile index 3705f58..b59c2ae 100644 --- a/Makefile +++ b/Makefile @@ -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 \ diff --git a/package.json b/package.json index 14545c7..4f58d6e 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "dependencies": { "async": "0.1.18", "pg": "0.6.18", + "mysql": "2.0.0-alpha3", "underscore": "1.3.3" }, "devDependencies": { diff --git a/test/bootstrap/init_mysql.js b/test/bootstrap/init_mysql.js new file mode 100644 index 0000000..3691e3c --- /dev/null +++ b/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() } + } + ) +}) diff --git a/test/bootstrap/init.js b/test/bootstrap/init_pg.js similarity index 93% rename from test/bootstrap/init.js rename to test/bootstrap/init_pg.js index 2c2f282..987c853 100644 --- a/test/bootstrap/init.js +++ b/test/bootstrap/init_pg.js @@ -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(); } } ); }