mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-28 02:17:11 +01:00
Fix: Create database before connect
This commit is contained in:
parent
f2633a5d01
commit
8d5679a8ab
@ -7,6 +7,7 @@ const knex = require("knex");
|
||||
const { PluginsManager } = require("./plugins-manager");
|
||||
const path = require("path");
|
||||
const { EmbeddedMariaDB } = require("./embedded-mariadb");
|
||||
const mysql = require("mysql2/promise");
|
||||
|
||||
/**
|
||||
* Database & App Data Folder
|
||||
@ -188,6 +189,19 @@ class Database {
|
||||
}
|
||||
};
|
||||
} else if (dbConfig.type === "mariadb") {
|
||||
if (!/^\w+$/.test(dbConfig.dbName)) {
|
||||
throw Error("Invalid Database name");
|
||||
}
|
||||
|
||||
const connection = await mysql.createConnection({
|
||||
host: dbConfig.hostname,
|
||||
port: dbConfig.port,
|
||||
user: dbConfig.username,
|
||||
password: dbConfig.password,
|
||||
});
|
||||
|
||||
await connection.execute("CREATE DATABASE IF NOT EXISTS " + dbConfig.dbName + " CHARACTER SET utf8mb4");
|
||||
|
||||
config = {
|
||||
client: "mysql2",
|
||||
connection: {
|
||||
|
Loading…
Reference in New Issue
Block a user