1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-23 19:02:37 +01:00

generalize primary column to work with mongodb object id

This commit is contained in:
Flam3rboy 2021-10-04 22:43:51 +02:00
parent b1c1b681b9
commit 7b63016872
16 changed files with 63 additions and 63 deletions

14
api/package-lock.json generated
View File

@ -31,7 +31,7 @@
"i18next-node-fs-backend": "^2.1.3",
"jsonwebtoken": "^8.5.1",
"lambert-server": "^1.2.10",
"missing-native-js-functions": "^1.2.15",
"missing-native-js-functions": "^1.2.16",
"mongoose": "^5.12.3",
"mongoose-autopopulate": "^0.12.3",
"mongoose-long": "^0.3.2",
@ -10653,9 +10653,9 @@
}
},
"node_modules/missing-native-js-functions": {
"version": "1.2.15",
"resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.15.tgz",
"integrity": "sha512-NNsxPSHnG22xellXsdGkzmF/SSzYNRgZcWQt2OKG+I3Wv8p37kTax13trTMthVkEOhvNv8M2l4A4JwK1p42ZHg=="
"version": "1.2.16",
"resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.16.tgz",
"integrity": "sha512-XiSrIpYeLfk6OMHoqgg1zxgpOS3dV2J4Elk/GVKqQ2zoRLEJTxPb6RXiAVCv5/JxutMypablImU9JOqV0Vpi9w=="
},
"node_modules/mixin-deep": {
"version": "1.3.2",
@ -24542,9 +24542,9 @@
}
},
"missing-native-js-functions": {
"version": "1.2.15",
"resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.15.tgz",
"integrity": "sha512-NNsxPSHnG22xellXsdGkzmF/SSzYNRgZcWQt2OKG+I3Wv8p37kTax13trTMthVkEOhvNv8M2l4A4JwK1p42ZHg=="
"version": "1.2.16",
"resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.16.tgz",
"integrity": "sha512-XiSrIpYeLfk6OMHoqgg1zxgpOS3dV2J4Elk/GVKqQ2zoRLEJTxPb6RXiAVCv5/JxutMypablImU9JOqV0Vpi9w=="
},
"mixin-deep": {
"version": "1.3.2",

View File

@ -92,7 +92,7 @@
"i18next-node-fs-backend": "^2.1.3",
"jsonwebtoken": "^8.5.1",
"lambert-server": "^1.2.10",
"missing-native-js-functions": "^1.2.15",
"missing-native-js-functions": "^1.2.16",
"mongoose": "^5.12.3",
"mongoose-autopopulate": "^0.12.3",
"mongoose-long": "^0.3.2",

View File

@ -17,7 +17,7 @@
"async-exit-hook": "^2.0.1",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"missing-native-js-functions": "^1.2.15",
"missing-native-js-functions": "^1.2.16",
"nanocolors": "^0.2.12",
"node-os-utils": "^1.3.5",
"tsconfig-paths": "^3.11.0"
@ -71,7 +71,7 @@
"i18next-node-fs-backend": "^2.1.3",
"jsonwebtoken": "^8.5.1",
"lambert-server": "^1.2.10",
"missing-native-js-functions": "^1.2.15",
"missing-native-js-functions": "^1.2.16",
"mongoose": "^5.12.3",
"mongoose-autopopulate": "^0.12.3",
"mongoose-long": "^0.3.2",
@ -138,7 +138,7 @@
"jest": "^27.0.6",
"lambert-db": "^1.2.3",
"lambert-server": "^1.2.8",
"missing-native-js-functions": "^1.2.15",
"missing-native-js-functions": "^1.2.16",
"multer": "^1.4.2",
"nanocolors": "^0.2.12",
"node-fetch": "^2.6.1",
@ -177,7 +177,7 @@
"dotenv": "^8.2.0",
"jsonwebtoken": "^8.5.1",
"lambert-server": "^1.2.8",
"missing-native-js-functions": "^1.2.15",
"missing-native-js-functions": "^1.2.16",
"mongoose-autopopulate": "^0.12.3",
"node-fetch": "^2.6.1",
"typeorm": "^0.2.37",
@ -216,7 +216,7 @@
"env-paths": "^2.2.1",
"jsonwebtoken": "^8.5.1",
"lambert-server": "^1.2.10",
"missing-native-js-functions": "^1.2.15",
"missing-native-js-functions": "^1.2.16",
"multer": "^1.4.3",
"nanocolors": "^0.2.12",
"node-fetch": "^2.6.1",
@ -1259,9 +1259,9 @@
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
},
"node_modules/missing-native-js-functions": {
"version": "1.2.15",
"resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.15.tgz",
"integrity": "sha512-NNsxPSHnG22xellXsdGkzmF/SSzYNRgZcWQt2OKG+I3Wv8p37kTax13trTMthVkEOhvNv8M2l4A4JwK1p42ZHg=="
"version": "1.2.16",
"resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.16.tgz",
"integrity": "sha512-XiSrIpYeLfk6OMHoqgg1zxgpOS3dV2J4Elk/GVKqQ2zoRLEJTxPb6RXiAVCv5/JxutMypablImU9JOqV0Vpi9w=="
},
"node_modules/ms": {
"version": "2.0.0",
@ -1757,7 +1757,7 @@
"jest-runtime": "^27.2.1",
"jsonwebtoken": "^8.5.1",
"lambert-server": "^1.2.10",
"missing-native-js-functions": "^1.2.15",
"missing-native-js-functions": "^1.2.16",
"mongoose": "^5.12.3",
"mongoose-autopopulate": "^0.12.3",
"mongoose-long": "^0.3.2",
@ -1808,7 +1808,7 @@
"jest": "^27.0.6",
"lambert-db": "^1.2.3",
"lambert-server": "^1.2.8",
"missing-native-js-functions": "^1.2.15",
"missing-native-js-functions": "^1.2.16",
"multer": "^1.4.2",
"nanocolors": "^0.2.12",
"node-fetch": "^2.6.1",
@ -1838,7 +1838,7 @@
"dotenv": "^8.2.0",
"jsonwebtoken": "^8.5.1",
"lambert-server": "^1.2.8",
"missing-native-js-functions": "^1.2.15",
"missing-native-js-functions": "^1.2.16",
"mongoose-autopopulate": "^0.12.3",
"node-fetch": "^2.6.1",
"ts-node-dev": "^1.1.6",
@ -1866,7 +1866,7 @@
"jest": "^27.0.6",
"jsonwebtoken": "^8.5.1",
"lambert-server": "^1.2.10",
"missing-native-js-functions": "^1.2.15",
"missing-native-js-functions": "^1.2.16",
"multer": "^1.4.3",
"nanocolors": "^0.2.12",
"node-fetch": "^2.6.1",
@ -2658,9 +2658,9 @@
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
},
"missing-native-js-functions": {
"version": "1.2.15",
"resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.15.tgz",
"integrity": "sha512-NNsxPSHnG22xellXsdGkzmF/SSzYNRgZcWQt2OKG+I3Wv8p37kTax13trTMthVkEOhvNv8M2l4A4JwK1p42ZHg=="
"version": "1.2.16",
"resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.16.tgz",
"integrity": "sha512-XiSrIpYeLfk6OMHoqgg1zxgpOS3dV2J4Elk/GVKqQ2zoRLEJTxPb6RXiAVCv5/JxutMypablImU9JOqV0Vpi9w=="
},
"ms": {
"version": "2.0.0",

View File

@ -56,7 +56,7 @@
"async-exit-hook": "^2.0.1",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"missing-native-js-functions": "^1.2.15",
"missing-native-js-functions": "^1.2.16",
"nanocolors": "^0.2.12",
"node-os-utils": "^1.3.5",
"tsconfig-paths": "^3.11.0"

14
cdn/package-lock.json generated
View File

@ -24,7 +24,7 @@
"jest": "^27.0.6",
"lambert-db": "^1.2.3",
"lambert-server": "^1.2.8",
"missing-native-js-functions": "^1.2.15",
"missing-native-js-functions": "^1.2.16",
"multer": "^1.4.2",
"nanocolors": "^0.2.12",
"node-fetch": "^2.6.1",
@ -4094,9 +4094,9 @@
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
},
"node_modules/missing-native-js-functions": {
"version": "1.2.15",
"resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.15.tgz",
"integrity": "sha512-NNsxPSHnG22xellXsdGkzmF/SSzYNRgZcWQt2OKG+I3Wv8p37kTax13trTMthVkEOhvNv8M2l4A4JwK1p42ZHg=="
"version": "1.2.16",
"resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.16.tgz",
"integrity": "sha512-XiSrIpYeLfk6OMHoqgg1zxgpOS3dV2J4Elk/GVKqQ2zoRLEJTxPb6RXiAVCv5/JxutMypablImU9JOqV0Vpi9w=="
},
"node_modules/mkdirp": {
"version": "0.5.5",
@ -8865,9 +8865,9 @@
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
},
"missing-native-js-functions": {
"version": "1.2.15",
"resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.15.tgz",
"integrity": "sha512-NNsxPSHnG22xellXsdGkzmF/SSzYNRgZcWQt2OKG+I3Wv8p37kTax13trTMthVkEOhvNv8M2l4A4JwK1p42ZHg=="
"version": "1.2.16",
"resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.16.tgz",
"integrity": "sha512-XiSrIpYeLfk6OMHoqgg1zxgpOS3dV2J4Elk/GVKqQ2zoRLEJTxPb6RXiAVCv5/JxutMypablImU9JOqV0Vpi9w=="
},
"mkdirp": {
"version": "0.5.5",

View File

@ -54,7 +54,7 @@
"jest": "^27.0.6",
"lambert-db": "^1.2.3",
"lambert-server": "^1.2.8",
"missing-native-js-functions": "^1.2.15",
"missing-native-js-functions": "^1.2.16",
"multer": "^1.4.2",
"nanocolors": "^0.2.12",
"node-fetch": "^2.6.1",

View File

@ -16,7 +16,7 @@
"dotenv": "^8.2.0",
"jsonwebtoken": "^8.5.1",
"lambert-server": "^1.2.8",
"missing-native-js-functions": "^1.2.15",
"missing-native-js-functions": "^1.2.16",
"mongoose-autopopulate": "^0.12.3",
"node-fetch": "^2.6.1",
"typeorm": "^0.2.37",
@ -8351,8 +8351,9 @@
}
},
"node_modules/missing-native-js-functions": {
"version": "1.2.15",
"integrity": "sha512-NNsxPSHnG22xellXsdGkzmF/SSzYNRgZcWQt2OKG+I3Wv8p37kTax13trTMthVkEOhvNv8M2l4A4JwK1p42ZHg=="
"version": "1.2.16",
"resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.16.tgz",
"integrity": "sha512-XiSrIpYeLfk6OMHoqgg1zxgpOS3dV2J4Elk/GVKqQ2zoRLEJTxPb6RXiAVCv5/JxutMypablImU9JOqV0Vpi9w=="
},
"node_modules/mkdirp": {
"version": "1.0.4",
@ -15962,8 +15963,9 @@
}
},
"missing-native-js-functions": {
"version": "1.2.15",
"integrity": "sha512-NNsxPSHnG22xellXsdGkzmF/SSzYNRgZcWQt2OKG+I3Wv8p37kTax13trTMthVkEOhvNv8M2l4A4JwK1p42ZHg=="
"version": "1.2.16",
"resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.16.tgz",
"integrity": "sha512-XiSrIpYeLfk6OMHoqgg1zxgpOS3dV2J4Elk/GVKqQ2zoRLEJTxPb6RXiAVCv5/JxutMypablImU9JOqV0Vpi9w=="
},
"mkdirp": {
"version": "1.0.4",

View File

@ -35,7 +35,7 @@
"dotenv": "^8.2.0",
"jsonwebtoken": "^8.5.1",
"lambert-server": "^1.2.8",
"missing-native-js-functions": "^1.2.15",
"missing-native-js-functions": "^1.2.16",
"mongoose-autopopulate": "^0.12.3",
"node-fetch": "^2.6.1",
"typeorm": "^0.2.37",

14
util/package-lock.json generated
View File

@ -17,7 +17,7 @@
"env-paths": "^2.2.1",
"jsonwebtoken": "^8.5.1",
"lambert-server": "^1.2.10",
"missing-native-js-functions": "^1.2.15",
"missing-native-js-functions": "^1.2.16",
"multer": "^1.4.3",
"nanocolors": "^0.2.12",
"node-fetch": "^2.6.1",
@ -4717,9 +4717,9 @@
}
},
"node_modules/missing-native-js-functions": {
"version": "1.2.15",
"resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.15.tgz",
"integrity": "sha512-NNsxPSHnG22xellXsdGkzmF/SSzYNRgZcWQt2OKG+I3Wv8p37kTax13trTMthVkEOhvNv8M2l4A4JwK1p42ZHg=="
"version": "1.2.16",
"resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.16.tgz",
"integrity": "sha512-XiSrIpYeLfk6OMHoqgg1zxgpOS3dV2J4Elk/GVKqQ2zoRLEJTxPb6RXiAVCv5/JxutMypablImU9JOqV0Vpi9w=="
},
"node_modules/mkdirp": {
"version": "0.5.5",
@ -11138,9 +11138,9 @@
}
},
"missing-native-js-functions": {
"version": "1.2.15",
"resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.15.tgz",
"integrity": "sha512-NNsxPSHnG22xellXsdGkzmF/SSzYNRgZcWQt2OKG+I3Wv8p37kTax13trTMthVkEOhvNv8M2l4A4JwK1p42ZHg=="
"version": "1.2.16",
"resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.16.tgz",
"integrity": "sha512-XiSrIpYeLfk6OMHoqgg1zxgpOS3dV2J4Elk/GVKqQ2zoRLEJTxPb6RXiAVCv5/JxutMypablImU9JOqV0Vpi9w=="
},
"mkdirp": {
"version": "0.5.5",

View File

@ -44,7 +44,7 @@
"env-paths": "^2.2.1",
"jsonwebtoken": "^8.5.1",
"lambert-server": "^1.2.10",
"missing-native-js-functions": "^1.2.15",
"missing-native-js-functions": "^1.2.16",
"multer": "^1.4.3",
"nanocolors": "^0.2.12",
"node-fetch": "^2.6.1",

View File

@ -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 = {}) {

View File

@ -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,
},

View File

@ -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()

View File

@ -8,8 +8,6 @@ import {
JoinTable,
ManyToMany,
ManyToOne,
OneToMany,
PrimaryColumn,
PrimaryGeneratedColumn,
RelationId,
} from "typeorm";

View File

@ -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";

View File

@ -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