Skip to content

Commit

Permalink
feat: added models and migration scripts
Browse files Browse the repository at this point in the history
-Party
-ProjectLocation
-ProjectRatings
-RelatedProject
-Unit
-Vintage
  • Loading branch information
frantzarty committed Dec 1, 2021
1 parent 0b9a8c1 commit bdbe84e
Show file tree
Hide file tree
Showing 16 changed files with 484 additions and 0 deletions.
Empty file added .sequelizerc
Empty file.
20 changes: 20 additions & 0 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"development": {
"dialect": "sqlite",
"storage": "data.sqlite3"
},
"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"
}
}
23 changes: 23 additions & 0 deletions config/database.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"development": {
"username": "root",
"password": null,
"database": "database_development",
"host": "127.0.0.1",
"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"
}
}
30 changes: 30 additions & 0 deletions migrations/20211130200914-create-project-location.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('ProjectLocations', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
countryRegion: {
type: Sequelize.STRING
},
hostCountry: {
type: Sequelize.STRING
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('ProjectLocations');
}
};
36 changes: 36 additions & 0 deletions migrations/20211201130904-create-project-ratings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('ProjectRatings', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
ratingType: {
type: Sequelize.STRING
},
rating: {
type: Sequelize.NUMBER
},
link: {
type: Sequelize.STRING
},
scale: {
type: Sequelize.STRING
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('ProjectRatings');
}
};
33 changes: 33 additions & 0 deletions migrations/20211201131101-create-party.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('Parties', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
name: {
type: Sequelize.STRING
},
country: {
type: Sequelize.STRING
},
registry: {
type: Sequelize.STRING
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('Parties');
}
};
69 changes: 69 additions & 0 deletions migrations/20211201131518-create-unit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('Units', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
owner: {
type: Sequelize.STRING
},
buyer: {
type: Sequelize.STRING
},
registry: {
type: Sequelize.STRING
},
blockIdentifier: {
type: Sequelize.STRING
},
identifier: {
type: Sequelize.STRING
},
qualificationId: {
type: Sequelize.NUMBER
},
unitType: {
type: Sequelize.STRING
},
unitCount: {
type: Sequelize.NUMBER
},
unitStatus: {
type: Sequelize.STRING
},
unitStatusDate: {
type: Sequelize.DATE
},
transactionType: {
type: Sequelize.STRING
},
unitIssuanceLocation: {
type: Sequelize.STRING
},
unitLink: {
type: Sequelize.STRING
},
correspondingAdjustment: {
type: Sequelize.STRING
},
unitTag: {
type: Sequelize.STRING
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('Units');
}
};
39 changes: 39 additions & 0 deletions migrations/20211201131734-create-vintage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('Vintages', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
startDate: {
type: Sequelize.DATE
},
endDate: {
type: Sequelize.DATE
},
verificationApproach: {
type: Sequelize.STRING
},
verificationDate: {
type: Sequelize.DATE
},
verificationBody: {
type: Sequelize.STRING
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('Vintages');
}
};
33 changes: 33 additions & 0 deletions migrations/20211201131902-create-related-project.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('RelatedProjects', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
relatedProjectType: {
type: Sequelize.STRING
},
registry: {
type: Sequelize.STRING
},
note: {
type: Sequelize.STRING
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('RelatedProjects');
}
};
37 changes: 37 additions & 0 deletions models/index.js
Original file line number Diff line number Diff line change
@@ -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 = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes);
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;
25 changes: 25 additions & 0 deletions models/party.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';
const {
Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
class Party extends Model {
/**
* Helper method for defining associations.
* This method is not a part of Sequelize lifecycle.
* The `models/index` file will call this method automatically.
*/
static associate(models) {
// define association here
}
};
Party.init({
name: DataTypes.STRING,
country: DataTypes.STRING,
registry: DataTypes.STRING
}, {
sequelize,
modelName: 'Party',
});
return Party;
};
24 changes: 24 additions & 0 deletions models/projectlocation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';
const {
Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
class ProjectLocation extends Model {
/**
* Helper method for defining associations.
* This method is not a part of Sequelize lifecycle.
* The `models/index` file will call this method automatically.
*/
static associate(models) {
// define association here
}
};
ProjectLocation.init({
countryRegion: DataTypes.STRING,
hostCountry: DataTypes.STRING
}, {
sequelize,
modelName: 'ProjectLocation',
});
return ProjectLocation;
};
Loading

0 comments on commit bdbe84e

Please sign in to comment.