2024-02-06 15:18:06 +00:00
|
|
|
import defineRoleEmojiPair from './models/roleEmojiPairs.js';
|
|
|
|
import defineVoiceChannel from './models/voiceChannels.js';
|
|
|
|
import defineMessage from './models/messages.js';
|
2024-03-02 22:51:18 +00:00
|
|
|
import defineGuild from './models/guilds.js';
|
|
|
|
import defineRole from './models/roles.js';
|
2024-02-06 15:18:06 +00:00
|
|
|
import { Sequelize } from 'sequelize';
|
|
|
|
import { config } from 'dotenv';
|
2024-02-11 01:40:10 +00:00
|
|
|
|
2024-02-06 15:18:06 +00:00
|
|
|
config();
|
|
|
|
|
|
|
|
const { DB_NAME } = process.env;
|
2024-02-11 01:04:12 +00:00
|
|
|
/** The database instance used as an ORM in this project. */
|
2024-02-06 15:18:06 +00:00
|
|
|
const sequelize = new Sequelize({
|
|
|
|
storage: `${DB_NAME}.sqlite`,
|
|
|
|
dialect: 'sqlite',
|
|
|
|
logging: false
|
|
|
|
});
|
2024-02-07 20:02:37 +00:00
|
|
|
|
2024-03-02 22:51:18 +00:00
|
|
|
const Guild = defineGuild(sequelize);
|
|
|
|
Guild.hasMany(VoiceChannel, { foreignKey: 'guild', onDelete: 'CASCADE' });
|
|
|
|
Guild.hasMany(Message, { foreignKey: 'guild', onDelete: 'CASCADE' });
|
|
|
|
Guild.hasMany(Role, { foreignKey: 'guild', onDelete: 'CASCADE' });
|
|
|
|
|
|
|
|
const Role = defineRole(sequelize);
|
|
|
|
Role.hasMany(RoleEmojiPair, { foreignKey: 'role', onDelete: 'CASCADE' });
|
|
|
|
|
2024-02-06 15:18:06 +00:00
|
|
|
const RoleEmojiPair = defineRoleEmojiPair(sequelize);
|
2024-02-07 20:02:37 +00:00
|
|
|
|
2024-02-06 15:18:06 +00:00
|
|
|
const VoiceChannel = defineVoiceChannel(sequelize);
|
2024-02-07 20:02:37 +00:00
|
|
|
|
2024-02-06 15:18:06 +00:00
|
|
|
const Message = defineMessage(sequelize);
|
2024-02-07 20:02:37 +00:00
|
|
|
Message.hasMany(RoleEmojiPair, { foreignKey: 'message', onDelete: 'CASCADE' });
|
2024-02-06 15:18:06 +00:00
|
|
|
|
|
|
|
sequelize.sync();
|
2024-03-02 22:51:18 +00:00
|
|
|
export { sequelize, Guild, Role, RoleEmojiPair, VoiceChannel, Message };
|