diff --git a/convertDatabase.js b/convertDatabase.js new file mode 100644 index 0000000..b65b3f5 --- /dev/null +++ b/convertDatabase.js @@ -0,0 +1,26 @@ +const { Sequelize, DataTypes } = require('sequelize'); +require('./dbObjects.js'); +const { sequelize, BeatenGames } = require ('./dbObjects.js'); + +// Add a new column to the existing table +(async () => { + try { + await sequelize.sync(); + + await sequelize.getQueryInterface().addColumn( + 'BeatenGames', + 'status', + { + type: DataTypes.ENUM('planning', 'playing', 'beat'), + allowNull: false, + defaultValue: 'beat', + }, + ); + + console.log('New column added successfully'); + } catch (error) { + console.error('Error adding new column:', error); + } finally { + sequelize.sync(); + } +})(); \ No newline at end of file diff --git a/dbObjects.js b/dbObjects.js index 58f148c..6d16344 100644 --- a/dbObjects.js +++ b/dbObjects.js @@ -44,4 +44,4 @@ sequelize.sync({ alter: true }) console.log(err); }); -module.exports = { Users, Games, BeatenGames }; \ No newline at end of file +module.exports = { sequelize, Users, Games, BeatenGames }; \ No newline at end of file diff --git a/models/beatenGames.js b/models/beatenGames.js index f94d92b..c528737 100644 --- a/models/beatenGames.js +++ b/models/beatenGames.js @@ -1,5 +1,9 @@ module.exports = (sequelize, DataTypes) => { return sequelize.define('beatenGames', { + status: { + type: DataTypes.ENUM('planning', 'playing', 'beat'), + allowNull: true, + }, }, { timestamps: true, });