mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-01-18 18:38:07 +00:00
Fix: Create database before connect
This commit is contained in:
parent
f2633a5d01
commit
8d5679a8ab
1 changed files with 14 additions and 0 deletions
|
@ -7,6 +7,7 @@ const knex = require("knex");
|
||||||
const { PluginsManager } = require("./plugins-manager");
|
const { PluginsManager } = require("./plugins-manager");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const { EmbeddedMariaDB } = require("./embedded-mariadb");
|
const { EmbeddedMariaDB } = require("./embedded-mariadb");
|
||||||
|
const mysql = require("mysql2/promise");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database & App Data Folder
|
* Database & App Data Folder
|
||||||
|
@ -188,6 +189,19 @@ class Database {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else if (dbConfig.type === "mariadb") {
|
} 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 = {
|
config = {
|
||||||
client: "mysql2",
|
client: "mysql2",
|
||||||
connection: {
|
connection: {
|
||||||
|
|
Loading…
Reference in a new issue