Fix: Create database before connect

pull/3017/head
Nelson Chan 2 years ago
parent f2633a5d01
commit 8d5679a8ab

@ -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…
Cancel
Save