Add changelog database

This commit is contained in:
baz 2024-07-13 21:00:14 +01:00
parent ccfee4f8c0
commit 5fb39b28b3
4 changed files with 29 additions and 4 deletions

View File

@ -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) {

View File

@ -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');

View File

@ -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 };

15
models/changelog.js Normal file
View File

@ -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,
});
};