diff --git a/migrations/20230224190927-genericize-table-and-model-names.js b/migrations/20230224190927-genericize-table-and-model-names.js new file mode 100644 index 0000000..3a574e0 --- /dev/null +++ b/migrations/20230224190927-genericize-table-and-model-names.js @@ -0,0 +1,13 @@ +'use strict'; + +module.exports = { + async up(queryInterface, Sequelize) { + await queryInterface.renameTable('Bands', 'Groups'); + await queryInterface.renameColumn('Characters', 'bandId', 'groupId'); + }, + + async down(queryInterface, Sequelize) { + await queryInterface.renameColumn('Characters', 'groupId', 'bandId'); + await queryInterface.renameTable('Groups', 'Bands'); + } +}; diff --git a/models/character.js b/models/character.js index b31c782..c0fed7f 100644 --- a/models/character.js +++ b/models/character.js @@ -10,12 +10,12 @@ module.exports = (sequelize, DataTypes) => { * The `models/index` file will call this method automatically. */ static associate(models) { - Character.belongsTo(models.Band, { foreignKey: 'bandId', }); + Character.belongsTo(models.Group, { foreignKey: 'groupId', }); } } Character.init({ name: DataTypes.STRING, - bandId: DataTypes.INTEGER, + groupId: DataTypes.INTEGER, imageIdentifier: DataTypes.STRING, description: DataTypes.TEXT, enabled: DataTypes.BOOLEAN diff --git a/models/band.js b/models/group.js similarity index 80% rename from models/band.js rename to models/group.js index 70529ef..1bce531 100644 --- a/models/band.js +++ b/models/group.js @@ -3,7 +3,7 @@ const { Model } = require('sequelize'); module.exports = (sequelize, DataTypes) => { - class Band extends Model { + class Group extends Model { /** * Helper method for defining associations. * This method is not a part of Sequelize lifecycle. @@ -11,17 +11,17 @@ module.exports = (sequelize, DataTypes) => { */ static associate(models) { // define association here - Band.hasMany(models.Character); + Group.hasMany(models.Character); } } - Band.init({ + Group.init({ name: DataTypes.STRING, description: DataTypes.TEXT, imageURL: DataTypes.STRING, enabled: DataTypes.BOOLEAN }, { sequelize, - modelName: 'Band', + modelName: 'Group', }); - return Band; + return Group; }; \ No newline at end of file