Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setting up MySQL, migrations and dotenv
* uses db-migrate
- Loading branch information
1 parent
e862788
commit d45a7df
Showing
10 changed files
with
135 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
MYSQL_USER=root | ||
MYSQL_PASSWORD= | ||
MYSQL_HOST=127.0.0.1 | ||
MYSQL_DATABASE_NAME=demo | ||
MYSQL_TEST_DATABASE_NAME=demo_test |
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 |
---|---|---|
|
@@ -116,3 +116,4 @@ npm-debug.log | |
nbproject | ||
.idea | ||
.node_history | ||
.env |
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,11 @@ | ||
/** | ||
* UserController | ||
* | ||
* @description :: Server-side logic for managing users | ||
* @help :: See http://sailsjs.org/#!/documentation/concepts/Controllers | ||
*/ | ||
|
||
module.exports = { | ||
|
||
}; | ||
|
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,47 @@ | ||
/** | ||
* User.js | ||
* | ||
* @description :: This represents a user in the system. | ||
* @docs :: http://sailsjs.org/documentation/concepts/models-and-orm/models | ||
*/ | ||
module.exports = { | ||
attributes: { | ||
firstname: { | ||
type: 'string', | ||
required: 'true', | ||
}, | ||
surname: { | ||
type: 'string', | ||
required: 'true', | ||
}, | ||
password: { | ||
type: 'string', | ||
minLength: 10, | ||
required: true, | ||
}, | ||
email: { | ||
type: 'string', | ||
unique: true, | ||
index: true, | ||
required: true, | ||
}, | ||
terms: { | ||
type: 'boolean', | ||
required: true, | ||
boolean: true, | ||
}, | ||
toJSON: function(){ | ||
const obj = this.toObject(); | ||
delete obj.password; | ||
return obj; | ||
} | ||
}, | ||
beforeValidate: function(user, cb){ | ||
user.terms = (user.terms == 'on' || user.terms == true) ? true : undefined; | ||
cb(); | ||
}, | ||
beforeCreate: function(user, cb) { | ||
// hash password | ||
cb(); | ||
} | ||
} |
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,5 @@ | ||
require('dotenv').config(); | ||
|
||
/** | ||
* Bootstrap | ||
* (sails.config.bootstrap) | ||
|
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,10 @@ | ||
{ | ||
"dev": { | ||
"host": { "ENV" : "MYSQL_HOST" }, | ||
"user": { "ENV" : "MYSQL_USER" }, | ||
"password" : { "ENV" : "MYSQL_PASSWORD" }, | ||
"database": { "ENV" : "MYSQL_DATABASE_NAME" }, | ||
"driver": "mysql", | ||
"multipleStatements": true | ||
} | ||
} |
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,38 @@ | ||
'use strict'; | ||
|
||
var dbm; | ||
var type; | ||
var seed; | ||
|
||
/** | ||
* We receive the dbmigrate dependency from dbmigrate initially. | ||
* This enables us to not have to rely on NODE_PATH. | ||
*/ | ||
exports.setup = function(options, seedLink) { | ||
dbm = options.dbmigrate; | ||
type = dbm.dataType; | ||
seed = seedLink; | ||
}; | ||
|
||
exports.up = function(db) { | ||
return db.runSql("CREATE TABLE `user` (\ | ||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,\ | ||
`firstname` varchar(255) DEFAULT NULL,\ | ||
`surname` varchar(255) DEFAULT NULL,\ | ||
`email` varchar(255) DEFAULT NULL,\ | ||
`password` varchar(255) DEFAULT NULL,\ | ||
`terms` tinyint(1) DEFAULT '0',\ | ||
`createdAt` datetime DEFAULT NULL,\ | ||
`updatedAt` datetime DEFAULT NULL,\ | ||
PRIMARY KEY (`id`),\ | ||
UNIQUE KEY `email` (`email`)\ | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8"); | ||
}; | ||
|
||
exports.down = function(db) { | ||
return db.runSql("DROP TABLE `user`"); | ||
}; | ||
|
||
exports._meta = { | ||
"version": 1 | ||
}; |
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