From 7b56d96c3c08a776bbd91b6bcab8dd5e74112cf0 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Wed, 3 Apr 2024 19:29:32 +0200 Subject: [PATCH] defined (message-) keyword model --- database.js | 4 ++++ models/keywords.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 models/keywords.js diff --git a/database.js b/database.js index fefc21d..3480ea5 100644 --- a/database.js +++ b/database.js @@ -1,6 +1,7 @@ import defineRoleEmojiPair from './models/roleEmojiPairs.js'; import defineVoiceChannel from './models/voiceChannels.js'; import defineMessage from './models/messages.js'; +import defineKeyword from './models/keywords.js'; import defineGuild from './models/guilds.js'; import defineRole from './models/roles.js'; import { Sequelize } from 'sequelize'; @@ -16,6 +17,8 @@ const sequelize = new Sequelize({ logging: false }); +const Keyword = defineKeyword(sequelize); + const RoleEmojiPair = defineRoleEmojiPair(sequelize); const VoiceChannel = defineVoiceChannel(sequelize); @@ -27,6 +30,7 @@ const Role = defineRole(sequelize); Role.hasMany(RoleEmojiPair, { foreignKey: 'role', onDelete: 'CASCADE' }); const Guild = defineGuild(sequelize); +Guild.hasMany(Keyword, { foreignKey: 'guild', onDelete: 'CASCADE' }); Guild.hasMany(VoiceChannel, { foreignKey: 'guild', onDelete: 'CASCADE' }); Guild.hasMany(Message, { foreignKey: 'guild', onDelete: 'CASCADE' }); Guild.hasMany(Role, { foreignKey: 'guild', onDelete: 'CASCADE' }); diff --git a/models/keywords.js b/models/keywords.js new file mode 100644 index 0000000..c46950f --- /dev/null +++ b/models/keywords.js @@ -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 + } + }); +}