Skip to content

Commit

Permalink
db > fix error when running /setup and server doesn't have guild-wide…
Browse files Browse the repository at this point in the history
… config
  • Loading branch information
dsevillamartin committed Mar 10, 2024
1 parent 6250f9e commit 1412235
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/Models/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,14 @@ const Channel = bookshelf.Model.extend(
{
validKeys: ['repo', 'useEmbed', 'ignoreUnknown', 'secret'],

create(channel) {
if (!channel?.guild) return Promise.resolve();
async create(channel) {
if (!channel?.guild?.id) return Promise.resolve();

const Guild = bookshelf.model('Guild'); // regular import doesn't work due to circular deps

// prevent failing foreign key
if (!(await Guild.find(channel.guild.id)))
await Guild.create(channel.guild);

Log.info(`DB | Channels + <#${channel.id}>`);

Expand Down
2 changes: 1 addition & 1 deletion lib/Models/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module.exports = (bookshelf) =>
Log.addBreadcrumb({
category: 'db.find',
message: `${model.tableName} #${id} ${
withRelated ? `+ ${withRelated.join(', ')}` : ``
withRelated?.length ? `+ ${withRelated.join(', ')}` : ``
}`,
level: 'debug',
});
Expand Down

0 comments on commit 1412235

Please sign in to comment.