3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-16 14:11:50 +00:00
zeppelin/backend/ormconfig.js

60 lines
1.5 KiB
JavaScript
Raw Normal View History

2021-09-11 19:06:51 +03:00
const fs = require("fs");
const path = require("path");
2018-12-14 06:47:58 +02: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") });
} catch {
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") });
} catch {
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");
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
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",
supportBigNumbers: true,
bigNumberStrings: true,
dateStrings: true,
synchronize: false,
connectTimeout: 2000,
2021-09-12 21:47:03 +03:00
logging: ["error", "warn"],
maxQueryExecutionTime: 250,
2021-09-12 21:47:03 +03:00
// Entities
2018-12-14 06:47:58 +02:00
entities: [entities],
// Pool options
extra: {
typeCast(field, next) {
2021-09-11 19:06:51 +03:00
if (field.type === "DATETIME") {
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;
}
return next();
2021-09-11 19:06:51 +03:00
},
},
// Migrations
2018-12-14 06:47:58 +02:00
migrations: [migrations],
cli: {
migrationsDir,
},
};