Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Micah - updated make setup to create databases and config files for b…
…oth postgres and mysql.
- Loading branch information
Micah Silverman
committed
Oct 27, 2012
1 parent
4b74fe8
commit 6141eb6
Showing
5 changed files
with
84 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.DS_Store | ||
.fastlegs | ||
.fastlegs_pg | ||
.fastlegs_mysql | ||
node_modules |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() } | ||
} | ||
) | ||
}) |
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