2023-07-01 12:17:45 +00:00
|
|
|
import moment from "moment-timezone";
|
|
|
|
import path from "path";
|
|
|
|
import { DataSource } from "typeorm";
|
2024-03-17 18:49:31 +02:00
|
|
|
import { MysqlConnectionOptions } from "typeorm/driver/mysql/MysqlConnectionOptions.js";
|
2023-07-01 12:17:45 +00:00
|
|
|
import { env } from "../env";
|
|
|
|
import { backendDir } from "../paths";
|
2019-07-22 00:10:27 +03:00
|
|
|
|
2021-09-11 19:06:51 +03:00
|
|
|
moment.tz.setDefault("UTC");
|
2018-10-26 06:41:20 +03:00
|
|
|
|
2024-03-30 12:34:33 +00:00
|
|
|
const entities = path.relative(process.cwd(), path.resolve(backendDir, "dist/data/entities/*.js"));
|
|
|
|
const migrations = path.relative(process.cwd(), path.resolve(backendDir, "dist/migrations/*.js"));
|
2018-12-14 06:47:58 +02:00
|
|
|
|
2024-03-17 18:49:31 +02:00
|
|
|
type DbOpts = Pick<MysqlConnectionOptions, "host" | "port" | "username" | "password" | "database">;
|
2024-04-06 15:36:45 +00:00
|
|
|
const dbOpts: DbOpts =
|
|
|
|
env.NODE_ENV === "production"
|
|
|
|
? {
|
|
|
|
host: env.DB_HOST,
|
|
|
|
port: env.DB_PORT,
|
|
|
|
username: env.DB_USER,
|
|
|
|
password: env.DB_PASSWORD,
|
|
|
|
database: env.DB_DATABASE,
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
host: "mysql",
|
|
|
|
port: 3306,
|
|
|
|
username: "zeppelin",
|
|
|
|
password: env.DEVELOPMENT_MYSQL_PASSWORD,
|
|
|
|
database: "zeppelin",
|
|
|
|
};
|
2024-03-17 18:49:31 +02:00
|
|
|
|
2023-07-01 12:17:45 +00:00
|
|
|
export const dataSource = new DataSource({
|
2018-10-26 06:41:20 +03:00
|
|
|
type: "mysql",
|
2024-03-17 18:49:31 +02:00
|
|
|
...dbOpts,
|
2021-09-11 19:06:51 +03:00
|
|
|
charset: "utf8mb4",
|
2018-10-26 06:41:20 +03:00
|
|
|
supportBigNumbers: true,
|
|
|
|
bigNumberStrings: true,
|
|
|
|
dateStrings: true,
|
|
|
|
synchronize: false,
|
2018-12-15 16:29:38 +02:00
|
|
|
connectTimeout: 2000,
|
2018-10-26 06:41:20 +03:00
|
|
|
|
2021-10-05 23:28:16 +03:00
|
|
|
logging: ["error", "warn"],
|
2021-09-12 21:47:03 +03:00
|
|
|
|
2018-10-26 06:41:20 +03:00
|
|
|
// Entities
|
2018-12-14 06:47:58 +02:00
|
|
|
entities: [entities],
|
2018-10-26 06:41:20 +03:00
|
|
|
|
|
|
|
// Pool options
|
|
|
|
extra: {
|
|
|
|
typeCast(field, next) {
|
2021-09-11 19:06:51 +03:00
|
|
|
if (field.type === "DATETIME") {
|
2018-10-26 06:41:20 +03:00
|
|
|
const val = field.string();
|
2021-09-11 19:06:51 +03:00
|
|
|
return val != null ? moment.utc(val).format("YYYY-MM-DD HH:mm:ss") : null;
|
2018-10-26 06:41:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return next();
|
2021-09-11 19:06:51 +03:00
|
|
|
},
|
2018-10-26 06:41:20 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
// Migrations
|
2018-12-14 06:47:58 +02:00
|
|
|
migrations: [migrations],
|
2023-07-01 12:17:45 +00:00
|
|
|
});
|