dynamic db type
This commit is contained in:
parent
2f5d9d3f01
commit
c7e48c0334
3 changed files with 5 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
|||
DB_TYPE = (mysql|sqlite|...)
|
||||
DB_HOST = database_host
|
||||
DB_NAME = database_name
|
||||
DB_USERNAME = database_username
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import "dotenv/config";
|
||||
import "reflect-metadata";
|
||||
import { DataSource } from "typeorm";
|
||||
import { DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME } from "./env.defaults";
|
||||
import { DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME, DB_TYPE } from "./env.defaults";
|
||||
|
||||
import { user } from "./entity/user";
|
||||
import { refresh } from "./entity/refresh";
|
||||
|
@ -14,7 +14,7 @@ import { Invite1724579024939 } from "./migrations/1724579024939-invite";
|
|||
import { Permissions1724661484664 } from "./migrations/1724661484664-permissions";
|
||||
|
||||
const dataSource = new DataSource({
|
||||
type: "mysql",
|
||||
type: DB_TYPE as any,
|
||||
host: process.env.NODE_ENV || process.env.DBMODE ? "localhost" : DB_HOST,
|
||||
port: 3306,
|
||||
username: DB_USERNAME,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import "dotenv/config";
|
||||
import ms from "ms";
|
||||
|
||||
export const DB_TYPE = process.env.DB_TYPE ?? "mysql";
|
||||
export const DB_HOST = process.env.DB_HOST ?? "";
|
||||
export const DB_NAME = process.env.DB_NAME ?? "";
|
||||
export const DB_USERNAME = process.env.DB_USERNAME ?? "";
|
||||
|
@ -21,6 +22,7 @@ export const MAIL_SECURE = process.env.MAIL_SECURE ?? "false";
|
|||
export const CLUB_NAME = process.env.CLUB_NAME ?? "";
|
||||
|
||||
export function configCheck() {
|
||||
if (DB_TYPE == "" ?? typeof DB_TYPE != "string") throw new Error("set valid value to DB_TYPE");
|
||||
if (DB_HOST == "" ?? typeof DB_HOST != "string") throw new Error("set valid value to DB_HOST");
|
||||
if (DB_NAME == "" ?? typeof DB_NAME != "string") throw new Error("set valid value to DB_NAME");
|
||||
if (DB_USERNAME == "" ?? typeof DB_USERNAME != "string") throw new Error("set valid value to DB_USERNAME");
|
||||
|
|
Loading…
Reference in a new issue