2021-09-11 19:06:51 +03:00
|
|
|
const fs = require("fs");
|
|
|
|
const path = require("path");
|
2018-12-14 06:47:58 +02:00
|
|
|
|
2019-07-22 00:10:27 +03:00
|
|
|
try {
|
2021-09-11 19:06:51 +03:00
|
|
|
fs.accessSync(path.resolve(__dirname, "bot.env"));
|
|
|
|
require("dotenv").config({ path: path.resolve(__dirname, "bot.env") });
|
2021-05-06 19:23:47 +01:00
|
|
|
} catch {
|
2019-07-22 00:10:27 +03:00
|
|
|
try {
|
2021-09-11 19:06:51 +03:00
|
|
|
fs.accessSync(path.resolve(__dirname, "api.env"));
|
|
|
|
require("dotenv").config({ path: path.resolve(__dirname, "api.env") });
|
2021-05-06 19:23:47 +01:00
|
|
|
} catch {
|
2019-07-22 00:10:27 +03:00
|
|
|
throw new Error("bot.env or api.env required");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-11 19:06:51 +03:00
|
|
|
const moment = require("moment-timezone");
|
|
|
|
moment.tz.setDefault("UTC");
|
2018-10-26 06:41:20 +03:00
|
|
|
|
2021-09-11 19:06:51 +03:00
|
|
|
const entities = path.relative(process.cwd(), path.resolve(__dirname, "dist/backend/src/data/entities/*.js"));
|
|
|
|
const migrations = path.relative(process.cwd(), path.resolve(__dirname, "dist/backend/src/migrations/*.js"));
|
|
|
|
const migrationsDir = path.relative(process.cwd(), path.resolve(__dirname, "src/migrations"));
|
2018-12-14 06:47:58 +02:00
|
|
|
|
2018-10-26 06:41:20 +03:00
|
|
|
module.exports = {
|
|
|
|
type: "mysql",
|
|
|
|
host: process.env.DB_HOST,
|
|
|
|
username: process.env.DB_USER,
|
|
|
|
password: process.env.DB_PASSWORD,
|
|
|
|
database: process.env.DB_DATABASE,
|
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],
|
2018-10-26 06:41:20 +03:00
|
|
|
cli: {
|
2019-11-30 23:38:11 +02:00
|
|
|
migrationsDir,
|
2018-10-26 06:41:20 +03:00
|
|
|
},
|
|
|
|
};
|