Add changelog database
This commit is contained in:
parent
ccfee4f8c0
commit
5fb39b28b3
|
@ -1,4 +1,4 @@
|
||||||
const { Users, Games, LoggedGames } = require ('./dbObjects.js');
|
const { Users, Games, LoggedGames, Changelog } = require ('./dbObjects.js');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
async function checkUserRegistration(user) {
|
async function checkUserRegistration(user) {
|
||||||
|
|
|
@ -10,6 +10,7 @@ const sequelize = new Sequelize('database', 'username', 'password', {
|
||||||
const db = require('./models/games.js')(sequelize, Sequelize.DataTypes);
|
const db = require('./models/games.js')(sequelize, Sequelize.DataTypes);
|
||||||
require('./models/users.js')(sequelize, Sequelize.DataTypes);
|
require('./models/users.js')(sequelize, Sequelize.DataTypes);
|
||||||
require('./models/beatenGames.js')(sequelize, Sequelize.DataTypes);
|
require('./models/beatenGames.js')(sequelize, Sequelize.DataTypes);
|
||||||
|
require('./models/changelog.js')(sequelize, Sequelize.DataTypes);
|
||||||
|
|
||||||
const force = process.argv.includes('--force') || process.argv.includes('-f');
|
const force = process.argv.includes('--force') || process.argv.includes('-f');
|
||||||
|
|
||||||
|
|
15
dbObjects.js
15
dbObjects.js
|
@ -10,15 +10,24 @@ const sequelize = new Sequelize('database', 'username', 'password', {
|
||||||
const Users = require('./models/users.js')(sequelize, Sequelize.DataTypes);
|
const Users = require('./models/users.js')(sequelize, Sequelize.DataTypes);
|
||||||
const Games = require('./models/games.js')(sequelize, Sequelize.DataTypes);
|
const Games = require('./models/games.js')(sequelize, Sequelize.DataTypes);
|
||||||
const LoggedGames = require('./models/beatenGames.js')(sequelize, Sequelize.DataTypes);
|
const LoggedGames = require('./models/beatenGames.js')(sequelize, Sequelize.DataTypes);
|
||||||
|
const Changelog = require('./models/changelog.js')(sequelize, Sequelize.DataTypes);
|
||||||
|
|
||||||
// Create userId foreignKey
|
// Create userId foreignKey in LoggedGames
|
||||||
Users.hasMany(LoggedGames);
|
Users.hasMany(LoggedGames);
|
||||||
LoggedGames.belongsTo(Users);
|
LoggedGames.belongsTo(Users);
|
||||||
|
|
||||||
// Create gameId foreignKey
|
// Create gameId foreignKey in LoggedGames
|
||||||
Games.hasMany(LoggedGames);
|
Games.hasMany(LoggedGames);
|
||||||
LoggedGames.belongsTo(Games);
|
LoggedGames.belongsTo(Games);
|
||||||
|
|
||||||
|
// Create userId foreignKey in Changelog
|
||||||
|
Users.hasMany(Changelog);
|
||||||
|
Changelog.belongsTo(Users);
|
||||||
|
|
||||||
|
// Create gameId foreignKey in Changelog
|
||||||
|
Games.hasMany(Changelog);
|
||||||
|
Changelog.belongsTo(Games);
|
||||||
|
|
||||||
Reflect.defineProperty(Users.prototype, 'addUser', {
|
Reflect.defineProperty(Users.prototype, 'addUser', {
|
||||||
value: async function addUser(userData) {
|
value: async function addUser(userData) {
|
||||||
const user = await Users.findOne({
|
const user = await Users.findOne({
|
||||||
|
@ -44,4 +53,4 @@ sequelize.sync({ alter: true })
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = { sequelize, Users, Games, LoggedGames };
|
module.exports = { sequelize, Users, Games, LoggedGames, Changelog };
|
|
@ -0,0 +1,15 @@
|
||||||
|
module.exports = (sequelize, DataTypes) => {
|
||||||
|
return sequelize.define('changelog', {
|
||||||
|
oldStatus: {
|
||||||
|
type: DataTypes.ENUM('planning', 'playing', 'beat'),
|
||||||
|
allowNull: true,
|
||||||
|
},
|
||||||
|
newStatus: {
|
||||||
|
type: DataTypes.ENUM('planning', 'playing', 'beat'),
|
||||||
|
allowNull: true,
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
timestamps: true,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue