mirror of
https://github.com/wassname/HackFlowy.git
synced 2026-06-27 16:00:04 +08:00
Introduce sequelize migrations to create and migrate database tables and removed database scripts. See http://sequelizejs.com/docs/latest/migrations
Created seeds to initialize database with dummy tasks. Introduce config module to handle configurations per environment. See https://github.com/lorenwest/node-config Updated README.md to reflect changes.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"port": 3000,
|
||||
"database": {
|
||||
"options" : {
|
||||
"dialect": "sqlite",
|
||||
"storage": "db/development.sqlite"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
var config = {
|
||||
port: 3000,
|
||||
db: {
|
||||
user : '',
|
||||
password : '',
|
||||
name : '',
|
||||
options : {
|
||||
dialect: 'sqlite'
|
||||
}
|
||||
}
|
||||
};
|
||||
module.exports = config;
|
||||
@@ -1,3 +0,0 @@
|
||||
ALTER TABLE `tasks`
|
||||
ADD COLUMN `is_completed` CHAR(1)
|
||||
NOT NULL AFTER `parent_id` ;
|
||||
@@ -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 */;
|
||||
@@ -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);
|
||||
@@ -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){
|
||||
|
||||
Reference in New Issue
Block a user