diff --git a/src/util/entities/Channel.ts b/src/util/entities/Channel.ts
index 8b692ac7..0ccabd62 100644
--- a/src/util/entities/Channel.ts
+++ b/src/util/entities/Channel.ts
@@ -102,10 +102,11 @@ export class Channel extends BaseClass {
guild_id?: string;
@JoinColumn({ name: "guild_id" })
- @ManyToOne(() => Guild, {
+ @ManyToOne(() => Guild, (guild) => guild.channels, {
onDelete: "CASCADE",
+ nullable: true,
})
- guild: Guild;
+ guild?: Guild;
@Column({ nullable: true })
@RelationId((channel: Channel) => channel.parent)
@@ -571,7 +572,6 @@ export interface DMChannel extends Omit<Channel, "type" | "recipients"> {
export function isTextChannel(type: ChannelType): boolean {
switch (type) {
case ChannelType.GUILD_STORE:
- case ChannelType.GUILD_VOICE:
case ChannelType.GUILD_STAGE_VOICE:
case ChannelType.GUILD_CATEGORY:
case ChannelType.GUILD_FORUM:
@@ -580,6 +580,7 @@ export function isTextChannel(type: ChannelType): boolean {
case ChannelType.DM:
case ChannelType.GROUP_DM:
case ChannelType.GUILD_NEWS:
+ case ChannelType.GUILD_VOICE:
case ChannelType.GUILD_NEWS_THREAD:
case ChannelType.GUILD_PUBLIC_THREAD:
case ChannelType.GUILD_PRIVATE_THREAD:
diff --git a/src/util/entities/Emoji.ts b/src/util/entities/Emoji.ts
index 0bc2f423..4d851698 100644
--- a/src/util/entities/Emoji.ts
+++ b/src/util/entities/Emoji.ts
@@ -33,7 +33,7 @@ export class Emoji extends BaseClass {
guild_id: string;
@JoinColumn({ name: "guild_id" })
- @ManyToOne(() => Guild, {
+ @ManyToOne(() => Guild, (guild) => guild.emojis, {
onDelete: "CASCADE",
})
guild: Guild;
diff --git a/src/util/entities/Invite.ts b/src/util/entities/Invite.ts
index 7970c4f0..f7e54fbe 100644
--- a/src/util/entities/Invite.ts
+++ b/src/util/entities/Invite.ts
@@ -53,7 +53,7 @@ export class Invite extends BaseClassWithoutId {
guild_id: string;
@JoinColumn({ name: "guild_id" })
- @ManyToOne(() => Guild, {
+ @ManyToOne(() => Guild, (guild) => guild.invites, {
onDelete: "CASCADE",
})
guild: Guild;
diff --git a/src/util/entities/Member.ts b/src/util/entities/Member.ts
index e7b89976..16b18ab1 100644
--- a/src/util/entities/Member.ts
+++ b/src/util/entities/Member.ts
@@ -327,6 +327,7 @@ export class Member extends BaseClassWithoutId {
id: guild_id,
},
relations: PublicGuildRelations,
+ relationLoadStrategy: "query",
});
const memberCount = await Member.count({ where: { guild_id } });
diff --git a/src/util/entities/Role.ts b/src/util/entities/Role.ts
index 9a601f31..e8e5feda 100644
--- a/src/util/entities/Role.ts
+++ b/src/util/entities/Role.ts
@@ -23,12 +23,12 @@ import { Guild } from "./Guild";
@Entity("roles")
export class Role extends BaseClass {
- @Column({ nullable: true })
+ @Column()
@RelationId((role: Role) => role.guild)
guild_id: string;
@JoinColumn({ name: "guild_id" })
- @ManyToOne(() => Guild, {
+ @ManyToOne(() => Guild, (guild) => guild.roles, {
onDelete: "CASCADE",
})
guild: Guild;
diff --git a/src/util/entities/Sticker.ts b/src/util/entities/Sticker.ts
index cd07e65a..e9294f92 100644
--- a/src/util/entities/Sticker.ts
+++ b/src/util/entities/Sticker.ts
@@ -17,9 +17,9 @@
*/
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
-import { User } from "./User";
import { BaseClass } from "./BaseClass";
import { Guild } from "./Guild";
+import { User } from "./User";
export enum StickerType {
STANDARD = 1,
@@ -62,7 +62,7 @@ export class Sticker extends BaseClass {
guild_id?: string;
@JoinColumn({ name: "guild_id" })
- @ManyToOne(() => Guild, {
+ @ManyToOne(() => Guild, (guild) => guild.stickers, {
onDelete: "CASCADE",
})
guild?: Guild;
diff --git a/src/util/entities/VoiceState.ts b/src/util/entities/VoiceState.ts
index b291c4d3..84b0ca71 100644
--- a/src/util/entities/VoiceState.ts
+++ b/src/util/entities/VoiceState.ts
@@ -20,8 +20,8 @@ import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass";
import { Channel } from "./Channel";
import { Guild } from "./Guild";
-import { User } from "./User";
import { Member } from "./Member";
+import { User } from "./User";
//https://gist.github.com/vassjozsef/e482c65df6ee1facaace8b3c9ff66145#file-voice_state-ex
@Entity("voice_states")
@@ -31,7 +31,7 @@ export class VoiceState extends BaseClass {
guild_id: string;
@JoinColumn({ name: "guild_id" })
- @ManyToOne(() => Guild, {
+ @ManyToOne(() => Guild, (guild) => guild.voice_states, {
onDelete: "CASCADE",
})
guild?: Guild;
diff --git a/src/util/util/Database.ts b/src/util/util/Database.ts
index a6b24b3e..3a45eea0 100644
--- a/src/util/util/Database.ts
+++ b/src/util/util/Database.ts
@@ -16,12 +16,12 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import { DataSource } from "typeorm";
-import { yellow, green, red } from "picocolors";
-import { Migration } from "../entities/Migration";
-import { ConfigEntity } from "../entities/Config";
import { config } from "dotenv";
import path from "path";
+import { green, red, yellow } from "picocolors";
+import { DataSource } from "typeorm";
+import { ConfigEntity } from "../entities/Config";
+import { Migration } from "../entities/Migration";
// UUID extension option is only supported with postgres
// We want to generate all id's with Snowflakes that's why we have our own BaseEntity class
@@ -50,7 +50,7 @@ const DataSourceOptions = new DataSource({
database: isSqlite ? dbConnectionString : undefined,
entities: [path.join(__dirname, "..", "entities", "*.js")],
synchronize: !!process.env.DB_SYNC,
- logging: false,
+ logging: !!process.env.DB_LOGGING,
bigNumberStrings: false,
supportBigNumbers: true,
name: "default",
@@ -129,7 +129,7 @@ export async function initDatabase(): Promise<DataSource> {
return dbConnection;
}
-export { dbConnection, DataSourceOptions, DatabaseType };
+export { DataSourceOptions, DatabaseType, dbConnection };
export async function closeDatabase() {
await dbConnection?.destroy();
diff --git a/src/util/util/Sentry.ts b/src/util/util/Sentry.ts
index e302da0c..74a23a1e 100644
--- a/src/util/util/Sentry.ts
+++ b/src/util/util/Sentry.ts
@@ -16,13 +16,12 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import { Config } from "./Config";
import { yellow } from "picocolors";
+import { Config } from "./Config";
-import express from "express";
-import * as SentryNode from "@sentry/node";
-import * as Tracing from "@sentry/tracing";
import * as Integrations from "@sentry/integrations";
+import * as SentryNode from "@sentry/node";
+import express from "express";
// Work around for when bundle calls api/etc
let errorHandlersUsed = false;
@@ -46,16 +45,28 @@ export const Sentry = {
);
}
+ const integrations = [
+ new SentryNode.Integrations.Http({ tracing: true }),
+ new Integrations.RewriteFrames({
+ root: __dirname,
+ }),
+ new SentryNode.Integrations.Http({
+ tracing: true,
+ breadcrumbs: true,
+ }),
+ ...SentryNode.autoDiscoverNodePerformanceMonitoringIntegrations(),
+ ];
+
+ if (app)
+ integrations.push(
+ new SentryNode.Integrations.Express({
+ app,
+ }),
+ );
+
SentryNode.init({
dsn: endpoint,
- integrations: [
- new SentryNode.Integrations.Http({ tracing: true }),
- new Tracing.Integrations.Express({ app }),
- new Tracing.Integrations.Mysql(),
- new Integrations.RewriteFrames({
- root: __dirname,
- }),
- ],
+ integrations,
tracesSampleRate: traceSampleRate, // naming?
environment,
});
|