diff --git a/README.md b/README.md index 6bf2180..e539c5a 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,9 @@ An open-source [Workflowy](http://workflowy.com) clone. ##Installation -* Copy over `sample.config.js` to `config.js`, and fill up the DB credentials. -* Create a new database and import `schema/hackflowy.sql`. +* Edit `config/development.json` to your needs * `npm install` +* Run migrations and initialize the database: `sequelize-cli -m --config config/database.json` and `node db/seed/initial_tasks.js` * `node server.js` ##Controls diff --git a/config/database.json b/config/database.json new file mode 100644 index 0000000..21940e1 --- /dev/null +++ b/config/database.json @@ -0,0 +1,17 @@ +{ + "development": { + "dialect": "sqlite", + "storage": "db/development.sqlite" + }, + "test": { + "dialect": "sqlite", + "storage": "db/test.sqlite" + }, + "production": { + "username": "root", + "password": null, + "database": "database_production", + "host": "127.0.0.1", + "dialect": "mysql" + } +} diff --git a/config/development.json b/config/development.json new file mode 100644 index 0000000..a0955ab --- /dev/null +++ b/config/development.json @@ -0,0 +1,9 @@ +{ + "port": 3000, + "database": { + "options" : { + "dialect": "sqlite", + "storage": "db/development.sqlite" + } + } +} diff --git a/db/models/task.js b/db/models/task.js new file mode 100644 index 0000000..22b4fd8 --- /dev/null +++ b/db/models/task.js @@ -0,0 +1,17 @@ +var Sequelize = require('sequelize'); + +module.exports = { + instance: function(orm) { + task = orm.define('Tasks', { + id : {type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true}, + content : {type: Sequelize.TEXT, allowNull: false}, + parent : Sequelize.INTEGER, + isCompleted: Sequelize.BOOLEAN, + createdAt : Sequelize.DATE, + updatedAt : Sequelize.DATE + }); + + orm.sync(); + return task; + } +} diff --git a/db/seed/initial_tasks.js b/db/seed/initial_tasks.js new file mode 100644 index 0000000..fe14b44 --- /dev/null +++ b/db/seed/initial_tasks.js @@ -0,0 +1,12 @@ +var config = require('config'), + orm = require('../../orm').configure(config.get('database')), + Tasks = require('../../db/models/task').instance(orm); + +Tasks.create({content: 'Welcome to HackFlowy!', isCompleted: false}); +Tasks.create({content: 'An open-source WorkFlowy clone', isCompleted: false}); +Tasks.create({content: 'Built using Backbone + Socket.IO', isCompleted: false}); +Tasks.create({content: 'I pulled this together in a few hours to learn Backbone', isCompleted: false}); +Tasks.create({content: 'Feel free to try it out and hack on it', isCompleted: false}); +Tasks.create({content: 'Good Luck!', isCompleted: false}); + +orm.sync(); diff --git a/migrations/20140807220204-create-tasks.js b/migrations/20140807220204-create-tasks.js new file mode 100644 index 0000000..e71132c --- /dev/null +++ b/migrations/20140807220204-create-tasks.js @@ -0,0 +1,19 @@ +module.exports = { + up: function(migration, DataTypes, done) { + migration.createTable( + 'Tasks', + { + id : {type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true}, + content : {type: DataTypes.TEXT, allowNull: false}, + parent : DataTypes.INTEGER, + isCompleted: DataTypes.BOOLEAN, + createdAt : DataTypes.DATE, + updatedAt : DataTypes.DATE + }); + done() + }, + down: function(migration, DataTypes, done) { + migration.dropTable('Tasks'); + done() + } +} diff --git a/models/task.js b/models/task.js deleted file mode 100644 index fd9893a..0000000 --- a/models/task.js +++ /dev/null @@ -1,14 +0,0 @@ -var Sequelize = require('sequelize'); - -module.exports = { - instance: function(orm) { - task = orm.define('Tasks', { - content: Sequelize.STRING, - parent: Sequelize.INTEGER, - is_completed: Sequelize.BOOLEAN - }); - - orm.sync(); - return task; - } -} diff --git a/package.json b/package.json index 5612c88..6a172b5 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "path": "~0.4.9", "mysql": "~2.0.0", "sqlite3": "~2.1.0", - "sequelize": "~2.0.0", - "socket.io": "*" + "sequelize": "~1.7.9", + "socket.io": "~1.0.6", + "config": "~1.0.2" } } diff --git a/sample.config.js b/sample.config.js deleted file mode 100644 index a402045..0000000 --- a/sample.config.js +++ /dev/null @@ -1,12 +0,0 @@ -var config = { - port: 3000, - db: { - user : '', - password : '', - name : '', - options : { - dialect: 'sqlite' - } - } -}; -module.exports = config; diff --git a/schema/alterTable.sql b/schema/alterTable.sql deleted file mode 100644 index 92b7f29..0000000 --- a/schema/alterTable.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE `tasks` -ADD COLUMN `is_completed` CHAR(1) -NOT NULL AFTER `parent_id` ; diff --git a/schema/hackflowy.sql b/schema/hackflowy.sql deleted file mode 100644 index fbce641..0000000 --- a/schema/hackflowy.sql +++ /dev/null @@ -1,51 +0,0 @@ --- phpMyAdmin SQL Dump --- version 3.5.7deb1 --- http://www.phpmyadmin.net --- --- Host: localhost --- Generation Time: Apr 10, 2013 at 09:51 PM --- Server version: 5.5.29-0ubuntu1 --- PHP Version: 5.4.9-4ubuntu2 - -SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; -SET time_zone = "+00:00"; - - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; - --- --- Database: `hackflowy` --- - --- -------------------------------------------------------- - --- --- Table structure for table `tasks` --- - -CREATE TABLE IF NOT EXISTS `tasks` ( - `id` int(10) NOT NULL AUTO_INCREMENT, - `content` varchar(1000) NOT NULL, - `timestamp` int(12) NOT NULL, - `parent_id` int(10) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=107 ; - --- --- Dumping data for table `tasks` --- - -INSERT INTO `tasks` (`id`, `content`, `timestamp`, `parent_id`) VALUES -(96, 'Welcome to HackFlowy!', 1365610846, 0), -(99, 'An open-source WorkFlowy clone', 1365610837, 0), -(101, 'Built using Backbone + Socket.IO', 1365610824, 0), -(102, 'I pulled this together in a few hours to learn Backbone', 1365610861, 0), -(104, 'Feel free to try it out and hack on it', 1365610859, 0), -(106, 'Good Luck!', 1365610865, 0); - -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/schema/postgres.sql b/schema/postgres.sql deleted file mode 100644 index 5d2823b..0000000 --- a/schema/postgres.sql +++ /dev/null @@ -1,19 +0,0 @@ - -CREATE TABLE IF NOT EXISTS "Tasks" ( - id serial primary key, - content varchar(1000) NOT NULL, - timestamp integer, - parent_id integer, - parent char(30), - is_completed boolean, - "updatedAt" TIMESTAMP WITH TIME ZONE, - "createdAt" TIMESTAMP WITH TIME ZONE -); - -INSERT INTO "Tasks" (id, content, timestamp, parent_id) VALUES -(96, 'Welcome to HackFlowy!', 1365610846, 0), -(99, 'An open-source WorkFlowy clone', 1365610837, 0), -(101, 'Built using Backbone + Socket.IO', 1365610824, 0), -(102, 'I pulled this together in a few hours to learn Backbone', 1365610861, 0), -(104, 'Feel free to try it out and hack on it', 1365610859, 0), -(106, 'Good Luck!', 1365610865, 0); diff --git a/server.js b/server.js index 2ba4d76..6140206 100644 --- a/server.js +++ b/server.js @@ -2,9 +2,9 @@ var application_root = __dirname, express = require('express'), app = express(), path = require('path'), - config = require('./config'), - orm = require('./orm').configure(config.db), - Tasks = require('./models/task').instance(orm), + config = require('config'), + orm = require('./orm').configure(config.get('database')), + Tasks = require('./db/models/task').instance(orm), server = require('http').createServer(app), io = require('socket.io').listen(server); @@ -16,9 +16,8 @@ app.configure(function() { app.use(express.errorHandler({dumpExceptions: true, showStack: true})); }); -var port = config.port; -server.listen(port, function() { - console.log( 'Express server listening on port %d in %s mode', port, app.settings.env ); +server.listen(config.get('port'), function() { + console.log( 'Express server listening on port %d in %s mode', config.get('port'), app.settings.env ); }); app.get('/tasks', function(req,res){