defined (message-) keyword model

This commit is contained in:
Baipyrus 2024-04-03 19:29:32 +02:00
parent d67242374e
commit 7b56d96c3c
2 changed files with 37 additions and 0 deletions

View File

@ -1,6 +1,7 @@
import defineRoleEmojiPair from './models/roleEmojiPairs.js'; import defineRoleEmojiPair from './models/roleEmojiPairs.js';
import defineVoiceChannel from './models/voiceChannels.js'; import defineVoiceChannel from './models/voiceChannels.js';
import defineMessage from './models/messages.js'; import defineMessage from './models/messages.js';
import defineKeyword from './models/keywords.js';
import defineGuild from './models/guilds.js'; import defineGuild from './models/guilds.js';
import defineRole from './models/roles.js'; import defineRole from './models/roles.js';
import { Sequelize } from 'sequelize'; import { Sequelize } from 'sequelize';
@ -16,6 +17,8 @@ const sequelize = new Sequelize({
logging: false logging: false
}); });
const Keyword = defineKeyword(sequelize);
const RoleEmojiPair = defineRoleEmojiPair(sequelize); const RoleEmojiPair = defineRoleEmojiPair(sequelize);
const VoiceChannel = defineVoiceChannel(sequelize); const VoiceChannel = defineVoiceChannel(sequelize);
@ -27,6 +30,7 @@ const Role = defineRole(sequelize);
Role.hasMany(RoleEmojiPair, { foreignKey: 'role', onDelete: 'CASCADE' }); Role.hasMany(RoleEmojiPair, { foreignKey: 'role', onDelete: 'CASCADE' });
const Guild = defineGuild(sequelize); const Guild = defineGuild(sequelize);
Guild.hasMany(Keyword, { foreignKey: 'guild', onDelete: 'CASCADE' });
Guild.hasMany(VoiceChannel, { foreignKey: 'guild', onDelete: 'CASCADE' }); Guild.hasMany(VoiceChannel, { foreignKey: 'guild', onDelete: 'CASCADE' });
Guild.hasMany(Message, { foreignKey: 'guild', onDelete: 'CASCADE' }); Guild.hasMany(Message, { foreignKey: 'guild', onDelete: 'CASCADE' });
Guild.hasMany(Role, { foreignKey: 'guild', onDelete: 'CASCADE' }); Guild.hasMany(Role, { foreignKey: 'guild', onDelete: 'CASCADE' });

33
models/keywords.js Normal file
View File

@ -0,0 +1,33 @@
import { DataTypes, Deferrable, Sequelize } from 'sequelize';
/**
* @typedef {Object} Keyword
* @property {string} id A universally unique id, generated by sequelize.
* @property {string} guild A Discord guild ID as a foreign key reference.
* @property {string} name The name of the keyword.
*/
/**
* The definition of the `Keyword` table in the database.
* @param {Sequelize} sequelize
*/
export default function (sequelize) {
return sequelize.define('Keywords', {
id: {
defaultValue: DataTypes.UUIDV4,
type: DataTypes.UUID,
primaryKey: true
},
guild: {
type: DataTypes.STRING,
references: {
deferrable: Deferrable.INITIALLY_IMMEDIATE,
model: 'Guilds',
key: 'id'
}
},
name: {
type: DataTypes.STRING
}
});
}