Added migrations
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
# How to deploy automatically:
|
||||
|
||||
1. set up aws cli with aws configure
|
||||
2. cd ma-api
|
||||
3. serverless deploy
|
||||
|
||||
|
||||
23
ma-api/lib/config/config.json
Normal file
23
ma-api/lib/config/config.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"development": {
|
||||
"username": "javimistaging",
|
||||
"password": "10MinutaSvaki*Dan",
|
||||
"database": "database_development",
|
||||
"host": "javimi-staging.cluster-c52xdqogwrl2.eu-central-1.rds.amazonaws.com",
|
||||
"dialect": "mysql"
|
||||
},
|
||||
"test": {
|
||||
"username": "root",
|
||||
"password": null,
|
||||
"database": "database_test",
|
||||
"host": "127.0.0.1",
|
||||
"dialect": "mysql"
|
||||
},
|
||||
"production": {
|
||||
"username": "root",
|
||||
"password": null,
|
||||
"database": "database_production",
|
||||
"host": "127.0.0.1",
|
||||
"dialect": "mysql"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
const Sequelize = require("sequelize");
|
||||
const sequelize = new Sequelize("sql7276322", "sql7276322", "RS53ihYlg9", {
|
||||
const sequelize = new Sequelize("sql7276322", "sql7276322@localhost", "RS53ihYlg9", {
|
||||
host: "sql7.freemysqlhosting.net",
|
||||
dialect: "mysql",
|
||||
operatorsAliases: false
|
||||
|
||||
27
ma-api/lib/migrations/20190310042110-create-market-alert.js
Normal file
27
ma-api/lib/migrations/20190310042110-create-market-alert.js
Normal file
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.createTable('MarketAlerts', {
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: Sequelize.INTEGER
|
||||
},
|
||||
olx_url: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
createdAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
},
|
||||
updatedAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
}
|
||||
});
|
||||
},
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.dropTable('MarketAlerts');
|
||||
}
|
||||
};
|
||||
37
ma-api/lib/models/index.js
Normal file
37
ma-api/lib/models/index.js
Normal file
@@ -0,0 +1,37 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const Sequelize = require('sequelize');
|
||||
const basename = path.basename(__filename);
|
||||
const env = process.env.NODE_ENV || 'development';
|
||||
const config = require(__dirname + '/../config/config.json')[env];
|
||||
const db = {};
|
||||
|
||||
let sequelize;
|
||||
if (config.use_env_variable) {
|
||||
sequelize = new Sequelize(process.env[config.use_env_variable], config);
|
||||
} else {
|
||||
sequelize = new Sequelize(config.database, config.username, config.password, config);
|
||||
}
|
||||
|
||||
fs
|
||||
.readdirSync(__dirname)
|
||||
.filter(file => {
|
||||
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
|
||||
})
|
||||
.forEach(file => {
|
||||
const model = sequelize['import'](path.join(__dirname, file));
|
||||
db[model.name] = model;
|
||||
});
|
||||
|
||||
Object.keys(db).forEach(modelName => {
|
||||
if (db[modelName].associate) {
|
||||
db[modelName].associate(db);
|
||||
}
|
||||
});
|
||||
|
||||
db.sequelize = sequelize;
|
||||
db.Sequelize = Sequelize;
|
||||
|
||||
module.exports = db;
|
||||
10
ma-api/lib/models/marketalert.js
Normal file
10
ma-api/lib/models/marketalert.js
Normal file
@@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const MarketAlert = sequelize.define('MarketAlert', {
|
||||
olx_url: DataTypes.STRING
|
||||
}, {});
|
||||
MarketAlert.associate = function(models) {
|
||||
// associations can be defined here
|
||||
};
|
||||
return MarketAlert;
|
||||
};
|
||||
750
ma-api/package-lock.json
generated
750
ma-api/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -15,6 +15,7 @@
|
||||
"express": "^4.16.4",
|
||||
"mysql2": "^1.6.4",
|
||||
"node-fetch": "^2.3.0",
|
||||
"sequelize": "^4.42.0"
|
||||
"sequelize": "^4.42.0",
|
||||
"sequelize-cli": "^5.4.0"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user