DB: Generalize table and model names
This commit is contained in:
@@ -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');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -10,12 +10,12 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
* The `models/index` file will call this method automatically.
|
* The `models/index` file will call this method automatically.
|
||||||
*/
|
*/
|
||||||
static associate(models) {
|
static associate(models) {
|
||||||
Character.belongsTo(models.Band, { foreignKey: 'bandId', });
|
Character.belongsTo(models.Group, { foreignKey: 'groupId', });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Character.init({
|
Character.init({
|
||||||
name: DataTypes.STRING,
|
name: DataTypes.STRING,
|
||||||
bandId: DataTypes.INTEGER,
|
groupId: DataTypes.INTEGER,
|
||||||
imageIdentifier: DataTypes.STRING,
|
imageIdentifier: DataTypes.STRING,
|
||||||
description: DataTypes.TEXT,
|
description: DataTypes.TEXT,
|
||||||
enabled: DataTypes.BOOLEAN
|
enabled: DataTypes.BOOLEAN
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ const {
|
|||||||
Model
|
Model
|
||||||
} = require('sequelize');
|
} = require('sequelize');
|
||||||
module.exports = (sequelize, DataTypes) => {
|
module.exports = (sequelize, DataTypes) => {
|
||||||
class Band extends Model {
|
class Group extends Model {
|
||||||
/**
|
/**
|
||||||
* Helper method for defining associations.
|
* Helper method for defining associations.
|
||||||
* This method is not a part of Sequelize lifecycle.
|
* This method is not a part of Sequelize lifecycle.
|
||||||
@@ -11,17 +11,17 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
*/
|
*/
|
||||||
static associate(models) {
|
static associate(models) {
|
||||||
// define association here
|
// define association here
|
||||||
Band.hasMany(models.Character);
|
Group.hasMany(models.Character);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Band.init({
|
Group.init({
|
||||||
name: DataTypes.STRING,
|
name: DataTypes.STRING,
|
||||||
description: DataTypes.TEXT,
|
description: DataTypes.TEXT,
|
||||||
imageURL: DataTypes.STRING,
|
imageURL: DataTypes.STRING,
|
||||||
enabled: DataTypes.BOOLEAN
|
enabled: DataTypes.BOOLEAN
|
||||||
}, {
|
}, {
|
||||||
sequelize,
|
sequelize,
|
||||||
modelName: 'Band',
|
modelName: 'Group',
|
||||||
});
|
});
|
||||||
return Band;
|
return Group;
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user