diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-10-04 22:43:51 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-10-04 22:43:51 +0200 |
commit | 0914f424ceec738762e17a8ee787d589c8a8cbcb (patch) | |
tree | cbca25e5637833ec7c71d4a8a24091fe61fccad8 /util/src | |
parent | Merge branch 'master' of http://github.com/fosscord/fosscord-server (diff) | |
download | server-0914f424ceec738762e17a8ee787d589c8a8cbcb.tar.xz |
:sparkles: generalize primary column to work with mongodb object id
Diffstat (limited to 'util/src')
-rw-r--r-- | util/src/entities/BaseClass.ts | 8 | ||||
-rw-r--r-- | util/src/entities/Config.ts | 10 | ||||
-rw-r--r-- | util/src/entities/Invite.ts | 8 | ||||
-rw-r--r-- | util/src/entities/Member.ts | 2 | ||||
-rw-r--r-- | util/src/entities/Template.ts | 2 | ||||
-rw-r--r-- | util/src/util/Database.ts | 2 |
6 files changed, 15 insertions, 17 deletions
diff --git a/util/src/entities/BaseClass.ts b/util/src/entities/BaseClass.ts index d18757f2..f105086a 100644 --- a/util/src/entities/BaseClass.ts +++ b/util/src/entities/BaseClass.ts @@ -5,10 +5,8 @@ import { BeforeUpdate, EntityMetadata, FindConditions, - getConnection, - getManager, + ObjectIdColumn, PrimaryColumn, - RemoveOptions, } from "typeorm"; import { Snowflake } from "../util/Snowflake"; import "missing-native-js-functions"; @@ -117,8 +115,10 @@ export class BaseClassWithoutId extends BaseEntity { // } } +export const PrimaryIdColumn = process.env.DATABASE?.startsWith("mongodb") ? ObjectIdColumn : PrimaryColumn; + export class BaseClass extends BaseClassWithoutId { - @PrimaryColumn() + @PrimaryIdColumn() id: string; assign(props: any = {}) { diff --git a/util/src/entities/Config.ts b/util/src/entities/Config.ts index edce92a9..28926233 100644 --- a/util/src/entities/Config.ts +++ b/util/src/entities/Config.ts @@ -1,11 +1,11 @@ -import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn } from "typeorm"; -import { BaseClass, BaseClassWithoutId } from "./BaseClass"; +import { Column, Entity } from "typeorm"; +import { BaseClassWithoutId, PrimaryIdColumn } from "./BaseClass"; import crypto from "crypto"; import { Snowflake } from "../util/Snowflake"; @Entity("config") export class ConfigEntity extends BaseClassWithoutId { - @PrimaryColumn() + @PrimaryIdColumn() key: string; @Column({ type: "simple-json", nullable: true }) @@ -144,7 +144,7 @@ export interface ConfigValue { useDefaultAsOptimal: boolean; available: Region[]; }; - + guild: { showAllGuildsInDiscovery: boolean; }; @@ -299,7 +299,7 @@ export const DefaultConfigOptions: ConfigValue = { }, ], }, - + guild: { showAllGuildsInDiscovery: false, }, diff --git a/util/src/entities/Invite.ts b/util/src/entities/Invite.ts index 78545b02..82556fab 100644 --- a/util/src/entities/Invite.ts +++ b/util/src/entities/Invite.ts @@ -1,6 +1,6 @@ -import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn, RelationId } from "typeorm"; -import { Member } from "."; -import { BaseClass } from "./BaseClass"; +import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm"; +import { Member } from "./Member"; +import { BaseClass, PrimaryIdColumn } from "./BaseClass"; import { Channel } from "./Channel"; import { Guild } from "./Guild"; import { User } from "./User"; @@ -9,7 +9,7 @@ export const PublicInviteRelation = ["inviter", "guild", "channel"]; @Entity("invites") export class Invite extends BaseClass { - @PrimaryColumn() + @PrimaryIdColumn() code: string; @Column() diff --git a/util/src/entities/Member.ts b/util/src/entities/Member.ts index feb9c069..7d7ac40a 100644 --- a/util/src/entities/Member.ts +++ b/util/src/entities/Member.ts @@ -8,8 +8,6 @@ import { JoinTable, ManyToMany, ManyToOne, - OneToMany, - PrimaryColumn, PrimaryGeneratedColumn, RelationId, } from "typeorm"; diff --git a/util/src/entities/Template.ts b/util/src/entities/Template.ts index c9c32f42..1d952283 100644 --- a/util/src/entities/Template.ts +++ b/util/src/entities/Template.ts @@ -1,4 +1,4 @@ -import { Column, Entity, Index, JoinColumn, ManyToOne, PrimaryColumn, RelationId } from "typeorm"; +import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm"; import { BaseClass } from "./BaseClass"; import { Guild } from "./Guild"; import { User } from "./User"; diff --git a/util/src/util/Database.ts b/util/src/util/Database.ts index 5f622805..6445bd60 100644 --- a/util/src/util/Database.ts +++ b/util/src/util/Database.ts @@ -24,7 +24,7 @@ export function initDatabase() { url: isSqlite ? undefined : dbConnectionString, database: isSqlite ? dbConnectionString : undefined, entities: Object.values(Models).filter((x) => x.constructor.name !== "Object"), - synchronize: true, + synchronize: type !== "mongodb", logging: false, cache: { duration: 1000 * 3, // cache all find queries for 3 seconds |