Skip to content

Commit

Permalink
migrations, env2
Browse files Browse the repository at this point in the history
  • Loading branch information
mauryakrishna committed May 17, 2020
1 parent 9671720 commit bdef136
Show file tree
Hide file tree
Showing 18 changed files with 861 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dist
node_modules
node_modules
26 changes: 26 additions & 0 deletions database.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"dev": {
"driver": "mysql",
"host": "mysql",
"port": "3306",
"user": "root",
"password": "root",
"database": "exp"
},
"prod": {
"driver": "mysql",
"host": {
"ENV": "MYSQL_HOST"
},
"user": {
"ENV": "MYSQL_USER"
},
"password": {
"ENV": "MYSQL_PASSWORD"
},
"database": {
"ENV": "MYSQL_DATABASE"
}
},
"sql-file": true
}
3 changes: 3 additions & 0 deletions devenv.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"NODE_ENV": "development"
}
53 changes: 53 additions & 0 deletions migrations/20200517120347-experiences.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

var dbm;
var type;
var seed;
var fs = require('fs');
var path = require('path');
var Promise;

/**
* 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;
Promise = options.Promise;
};

exports.up = function(db) {
var filePath = path.join(__dirname, 'sqls', '20200517120347-experiences-up.sql');
return new Promise( function( resolve, reject ) {
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
if (err) return reject(err);
console.log('received data: ' + data);

resolve(data);
});
})
.then(function(data) {
return db.runSql(data);
});
};

exports.down = function(db) {
var filePath = path.join(__dirname, 'sqls', '20200517120347-experiences-down.sql');
return new Promise( function( resolve, reject ) {
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
if (err) return reject(err);
console.log('received data: ' + data);

resolve(data);
});
})
.then(function(data) {
return db.runSql(data);
});
};

exports._meta = {
"version": 1
};
53 changes: 53 additions & 0 deletions migrations/20200517131130-tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

var dbm;
var type;
var seed;
var fs = require('fs');
var path = require('path');
var Promise;

/**
* 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;
Promise = options.Promise;
};

exports.up = function(db) {
var filePath = path.join(__dirname, 'sqls', '20200517131130-tags-up.sql');
return new Promise( function( resolve, reject ) {
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
if (err) return reject(err);
console.log('received data: ' + data);

resolve(data);
});
})
.then(function(data) {
return db.runSql(data);
});
};

exports.down = function(db) {
var filePath = path.join(__dirname, 'sqls', '20200517131130-tags-down.sql');
return new Promise( function( resolve, reject ) {
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
if (err) return reject(err);
console.log('received data: ' + data);

resolve(data);
});
})
.then(function(data) {
return db.runSql(data);
});
};

exports._meta = {
"version": 1
};
53 changes: 53 additions & 0 deletions migrations/20200517131811-authors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

var dbm;
var type;
var seed;
var fs = require('fs');
var path = require('path');
var Promise;

/**
* 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;
Promise = options.Promise;
};

exports.up = function(db) {
var filePath = path.join(__dirname, 'sqls', '20200517131811-authors-up.sql');
return new Promise( function( resolve, reject ) {
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
if (err) return reject(err);
console.log('received data: ' + data);

resolve(data);
});
})
.then(function(data) {
return db.runSql(data);
});
};

exports.down = function(db) {
var filePath = path.join(__dirname, 'sqls', '20200517131811-authors-down.sql');
return new Promise( function( resolve, reject ) {
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
if (err) return reject(err);
console.log('received data: ' + data);

resolve(data);
});
})
.then(function(data) {
return db.runSql(data);
});
};

exports._meta = {
"version": 1
};
53 changes: 53 additions & 0 deletions migrations/20200517142433-followers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

var dbm;
var type;
var seed;
var fs = require('fs');
var path = require('path');
var Promise;

/**
* 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;
Promise = options.Promise;
};

exports.up = function(db) {
var filePath = path.join(__dirname, 'sqls', '20200517142433-followers-up.sql');
return new Promise( function( resolve, reject ) {
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
if (err) return reject(err);
console.log('received data: ' + data);

resolve(data);
});
})
.then(function(data) {
return db.runSql(data);
});
};

exports.down = function(db) {
var filePath = path.join(__dirname, 'sqls', '20200517142433-followers-down.sql');
return new Promise( function( resolve, reject ) {
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
if (err) return reject(err);
console.log('received data: ' + data);

resolve(data);
});
})
.then(function(data) {
return db.runSql(data);
});
};

exports._meta = {
"version": 1
};
2 changes: 2 additions & 0 deletions migrations/sqls/20200517120347-experiences-down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* Replace with your SQL commands */
DROP TABLE `experiences` IF EXISTS;
14 changes: 14 additions & 0 deletions migrations/sqls/20200517120347-experiences-up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* Replace with your SQL commands */
CREATE TABLE `experiences` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`authorid` bigint(10) NOT NULL,
`slug` varchar(255) NOT NULL DEFAULT '',
`title` varchar(500) NOT NULL DEFAULT '',
`experience` JSON,
`tags` varchar(1000) DEFAULT NULL,
`readcount` bigint(10) DEFAULT 0,
`publishdate` timestamp DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
2 changes: 2 additions & 0 deletions migrations/sqls/20200517131130-tags-down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* Replace with your SQL commands */
DROP TABLE `tags` IF EXISTS;
7 changes: 7 additions & 0 deletions migrations/sqls/20200517131130-tags-up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* Replace with your SQL commands */
CREATE TABLE `tags` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`tagname` varchar(50) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
2 changes: 2 additions & 0 deletions migrations/sqls/20200517131811-authors-down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* Replace with your SQL commands */
DROP TABLE `authors` IF EXISTS;
10 changes: 10 additions & 0 deletions migrations/sqls/20200517131811-authors-up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* Replace with your SQL commands */
CREATE TABLE `authors` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`displayname` varchar(100) DEFAULT NULL,
`email` varchar(1000) NOT NULL,
`smallintro` varchar(1000) DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
2 changes: 2 additions & 0 deletions migrations/sqls/20200517142433-followers-down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* Replace with your SQL commands */
DROP TABLE `followers` IF EXISTS;
9 changes: 9 additions & 0 deletions migrations/sqls/20200517142433-followers-up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* Replace with your SQL commands */
CREATE TABLE `followers` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`authorid` bigint(10) NOT NULL,
`followerid` bigint(10) NOT NULL,
FOREIGN KEY (`authorid`) REFERENCES `authors` (`id`),
FOREIGN KEY (`followerid`) REFERENCES `authors` (`id`),
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Loading

0 comments on commit bdef136

Please sign in to comment.