From fe50800613611f6552740cbd68e3b0db56690d3e Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Sun, 18 Dec 2022 21:54:20 +1100 Subject: Move to migrations. Use `npm run generate:db` for first database generation. --- package.json | 1 + scripts/syncronise.js | 19 +++++++++++++++++++ src/util/entities/BaseClass.ts | 1 - src/util/entities/Config.ts | 2 -- src/util/util/Database.ts | 7 ++----- 5 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 scripts/syncronise.js diff --git a/package.json b/package.json index 3aa6095e..4d893f92 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "start:gateway": "node dist/gateway/start.js", "build": "tsc -p .", "setup": "npm run build && npm run generate:schema", + "generate:db": "node scripts/syncronise.js", "generate:rights": "node scripts/rights.js", "generate:schema": "node scripts/schema.js", "generate:client": "node scripts/client.js", diff --git a/scripts/syncronise.js b/scripts/syncronise.js new file mode 100644 index 00000000..6ce47278 --- /dev/null +++ b/scripts/syncronise.js @@ -0,0 +1,19 @@ +/* + "Why?" I hear you say! "Why don't you just use `typeorm schema:sync`?"! + Because we have a lot ( like, 30? ) cyclic imports in the entities folder, + which breaks that command entirely! + + however! + it doesn't break the below, thus we're left with this :sob: +*/ + +require("module-alias/register"); +require("dotenv").config(); +const { initDatabase } = require(".."); + +(async () => { + const db = await initDatabase(); + console.log("synchronising"); + await db.synchronize(); + console.log("done"); +})(); \ No newline at end of file diff --git a/src/util/entities/BaseClass.ts b/src/util/entities/BaseClass.ts index cb97f513..025c747b 100644 --- a/src/util/entities/BaseClass.ts +++ b/src/util/entities/BaseClass.ts @@ -3,7 +3,6 @@ import { BaseEntity, BeforeInsert, BeforeUpdate, - DeepPartial, FindOptionsWhere, ObjectIdColumn, PrimaryColumn, diff --git a/src/util/entities/Config.ts b/src/util/entities/Config.ts index ff42b412..646737a0 100644 --- a/src/util/entities/Config.ts +++ b/src/util/entities/Config.ts @@ -2,9 +2,7 @@ import { Column, Entity } from "typeorm"; import { BaseClassWithoutId, PrimaryIdColumn } from "./BaseClass"; import crypto from "crypto"; import { Snowflake } from "../util/Snowflake"; -import { SessionsReplace } from ".."; import { hostname } from "os"; -import { Rights } from "../util/Rights"; @Entity("config") export class ConfigEntity extends BaseClassWithoutId { diff --git a/src/util/util/Database.ts b/src/util/util/Database.ts index f2190bfc..87ee212f 100644 --- a/src/util/util/Database.ts +++ b/src/util/util/Database.ts @@ -1,8 +1,6 @@ import path from "path"; import "reflect-metadata"; import { DataSource } from "typeorm"; -import * as Models from "../entities"; -import { Migration } from "../entities/Migration"; import { yellow, green, red } from "picocolors"; // UUID extension option is only supported with postgres @@ -44,13 +42,12 @@ export async function initDatabase(): Promise { url: isSqlite ? undefined : dbConnectionString, database: isSqlite ? dbConnectionString : undefined, entities: ["dist/util/entities/*.js"], - synchronize: type !== "mongodb", + synchronize: false, logging: false, bigNumberStrings: false, supportBigNumbers: true, name: "default", - // TODO migrations - // migrations: [path.join(__dirname, "..", "migrations", "*.js")], + migrations: ["dist/util/migrations/*.js"], }); dbConnection = await dataSource.initialize(); -- cgit 1.4.1