Move to migrations. Use npm run generate:db
for first database generation.
This commit is contained in:
parent
ed6aecf157
commit
32e9d1828c
@ -10,6 +10,7 @@
|
|||||||
"start:gateway": "node dist/gateway/start.js",
|
"start:gateway": "node dist/gateway/start.js",
|
||||||
"build": "tsc -p .",
|
"build": "tsc -p .",
|
||||||
"setup": "npm run build && npm run generate:schema",
|
"setup": "npm run build && npm run generate:schema",
|
||||||
|
"generate:db": "node scripts/syncronise.js",
|
||||||
"generate:rights": "node scripts/rights.js",
|
"generate:rights": "node scripts/rights.js",
|
||||||
"generate:schema": "node scripts/schema.js",
|
"generate:schema": "node scripts/schema.js",
|
||||||
"generate:client": "node scripts/client.js",
|
"generate:client": "node scripts/client.js",
|
||||||
|
19
scripts/syncronise.js
Normal file
19
scripts/syncronise.js
Normal file
@ -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");
|
||||||
|
})();
|
@ -3,7 +3,6 @@ import {
|
|||||||
BaseEntity,
|
BaseEntity,
|
||||||
BeforeInsert,
|
BeforeInsert,
|
||||||
BeforeUpdate,
|
BeforeUpdate,
|
||||||
DeepPartial,
|
|
||||||
FindOptionsWhere,
|
FindOptionsWhere,
|
||||||
ObjectIdColumn,
|
ObjectIdColumn,
|
||||||
PrimaryColumn,
|
PrimaryColumn,
|
||||||
|
@ -2,9 +2,7 @@ import { Column, Entity } from "typeorm";
|
|||||||
import { BaseClassWithoutId, PrimaryIdColumn } from "./BaseClass";
|
import { BaseClassWithoutId, PrimaryIdColumn } from "./BaseClass";
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
import { Snowflake } from "../util/Snowflake";
|
import { Snowflake } from "../util/Snowflake";
|
||||||
import { SessionsReplace } from "..";
|
|
||||||
import { hostname } from "os";
|
import { hostname } from "os";
|
||||||
import { Rights } from "../util/Rights";
|
|
||||||
|
|
||||||
@Entity("config")
|
@Entity("config")
|
||||||
export class ConfigEntity extends BaseClassWithoutId {
|
export class ConfigEntity extends BaseClassWithoutId {
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import { DataSource } from "typeorm";
|
import { DataSource } from "typeorm";
|
||||||
import * as Models from "../entities";
|
|
||||||
import { Migration } from "../entities/Migration";
|
|
||||||
import { yellow, green, red } from "picocolors";
|
import { yellow, green, red } from "picocolors";
|
||||||
|
|
||||||
// UUID extension option is only supported with postgres
|
// UUID extension option is only supported with postgres
|
||||||
@ -44,13 +42,12 @@ export async function initDatabase(): Promise<DataSource> {
|
|||||||
url: isSqlite ? undefined : dbConnectionString,
|
url: isSqlite ? undefined : dbConnectionString,
|
||||||
database: isSqlite ? dbConnectionString : undefined,
|
database: isSqlite ? dbConnectionString : undefined,
|
||||||
entities: ["dist/util/entities/*.js"],
|
entities: ["dist/util/entities/*.js"],
|
||||||
synchronize: type !== "mongodb",
|
synchronize: false,
|
||||||
logging: false,
|
logging: false,
|
||||||
bigNumberStrings: false,
|
bigNumberStrings: false,
|
||||||
supportBigNumbers: true,
|
supportBigNumbers: true,
|
||||||
name: "default",
|
name: "default",
|
||||||
// TODO migrations
|
migrations: ["dist/util/migrations/*.js"],
|
||||||
// migrations: [path.join(__dirname, "..", "migrations", "*.js")],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
dbConnection = await dataSource.initialize();
|
dbConnection = await dataSource.initialize();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user