Updated models and migrations to new spec

This commit is contained in:
2022-08-17 19:36:47 +02:00
parent bc075805e2
commit 05804cb78a
22 changed files with 336 additions and 86 deletions

28
models/band.js Normal file
View File

@@ -0,0 +1,28 @@
'use strict';
const {
Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
class Band extends Model {
/**
* Helper method for defining associations.
* This method is not a part of Sequelize lifecycle.
* The `models/index` file will call this method automatically.
*/
static associate(models) {
// define association here
Band.hasMany(models.Character);
}
}
Band.init({
uniqueId: DataTypes.INTEGER,
name: DataTypes.STRING,
description: DataTypes.TEXT,
imageURL: DataTypes.STRING,
enabled: DataTypes.BOOLEAN
}, {
sequelize,
modelName: 'Band',
});
return Band;
};

24
models/bot.js Normal file
View File

@@ -0,0 +1,24 @@
'use strict';
const {
Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
class Bot extends Model {
/**
* Helper method for defining associations.
* This method is not a part of Sequelize lifecycle.
* The `models/index` file will call this method automatically.
*/
static associate(models) {
// define association here
}
}
Bot.init({
maintenance: DataTypes.BOOLEAN,
adminIDs: DataTypes.STRING
}, {
sequelize,
modelName: 'Guild',
});
return Bot;
};

View File

@@ -10,22 +10,18 @@ module.exports = (sequelize, DataTypes) => {
* The `models/index` file will call this method automatically.
*/
static associate(models) {
Card.belongsTo(models.Character, {
foreignKey: 'characterID',
as: 'character'
});
Card.belongsTo(models.User, {
foreignKey: 'ownerID',
key: 'userId',
as: 'owner'
});
Card.belongsTo(models.User);
Card.belongsTo(models.Character);
}
}
Card.init({
ownerID: DataTypes.STRING,
identifier: DataTypes.STRING,
characterID: DataTypes.INTEGER,
enabled: { type: DataTypes.BOOLEAN, defaultValue: true }
characterId: DataTypes.INTEGER,
quality: DataTypes.INTEGER,
userId: DataTypes.STRING,
imageHash: DataTypes.STRING,
enabled: { type: DataTypes.BOOLEAN, defaultValue: true },
printNr: DataTypes.INTEGER,
}, {
sequelize,
modelName: 'Card',

View File

@@ -10,18 +10,16 @@ module.exports = (sequelize, DataTypes) => {
* The `models/index` file will call this method automatically.
*/
static associate(models) {
Character.hasMany(models.Card, {
foreignKey: 'characterID',
as: 'cards'
});
Character.belongsToMany(models.Card, { through: 'CardCharacter' });
Character.belongsTo(models.Band, { foreignKey: 'bandId', });
}
}
Character.init({
name: DataTypes.STRING,
rarity: DataTypes.INTEGER,
description: DataTypes.STRING,
bandId: DataTypes.INTEGER,
imageURL: DataTypes.STRING,
imageHash: DataTypes.STRING
description: DataTypes.TEXT,
enabled: DataTypes.BOOLEAN
}, {
sequelize,
modelName: 'Character',

View File

@@ -14,9 +14,9 @@ module.exports = (sequelize, DataTypes) => {
}
}
Guild.init({
guildID: DataTypes.STRING,
adminRoleID: DataTypes.STRING,
owderID: DataTypes.STRING
guildId: DataTypes.BIGINT,
adminRoleId: DataTypes.BIGINT,
active: DataTypes.INTEGER,
}, {
sequelize,
modelName: 'Guild',

View File

@@ -11,12 +11,13 @@ module.exports = (sequelize, DataTypes) => {
*/
static associate(models) {
// define association here
User.hasMany(models.Card);
}
}
User.init({
userID: DataTypes.STRING,
banned: DataTypes.BOOLEAN,
registredAt: DataTypes.DATE
discordId: DataTypes.BIGINT,
active: DataTypes.INTEGER,
privacy: DataTypes.INTEGER
}, {
sequelize,
modelName: 'User',