mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-11-06 18:35:14 +00:00
Attempt to fix race condition with database instantiation
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import knex from "knex";
|
import knex from "knex";
|
||||||
import {configGet, configHas} from "./lib/config.js";
|
import {configGet, configHas} from "./lib/config.js";
|
||||||
|
|
||||||
|
let instance = null;
|
||||||
|
|
||||||
const generateDbConfig = () => {
|
const generateDbConfig = () => {
|
||||||
if (!configHas("database")) {
|
if (!configHas("database")) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -30,4 +32,11 @@ const generateDbConfig = () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export default knex(generateDbConfig());
|
const getInstance = () => {
|
||||||
|
if (!instance) {
|
||||||
|
instance = knex(generateDbConfig());
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default getInstance;
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ import db from "./db.js";
|
|||||||
import { migrate as logger } from "./logger.js";
|
import { migrate as logger } from "./logger.js";
|
||||||
|
|
||||||
const migrateUp = async () => {
|
const migrateUp = async () => {
|
||||||
const version = await db.migrate.currentVersion();
|
const version = await db().migrate.currentVersion();
|
||||||
logger.info("Current database version:", version);
|
logger.info("Current database version:", version);
|
||||||
return await db.migrate.latest({
|
return await db().migrate.latest({
|
||||||
tableName: "migrations",
|
tableName: "migrations",
|
||||||
directory: "migrations",
|
directory: "migrations",
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import now from "./now_helper.js";
|
|||||||
import ProxyHostModel from "./proxy_host.js";
|
import ProxyHostModel from "./proxy_host.js";
|
||||||
import User from "./user.js";
|
import User from "./user.js";
|
||||||
|
|
||||||
Model.knex(db);
|
Model.knex(db());
|
||||||
|
|
||||||
const boolFields = ["is_deleted", "satisfy_any", "pass_auth"];
|
const boolFields = ["is_deleted", "satisfy_any", "pass_auth"];
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import db from "../db.js";
|
|||||||
import accessListModel from "./access_list.js";
|
import accessListModel from "./access_list.js";
|
||||||
import now from "./now_helper.js";
|
import now from "./now_helper.js";
|
||||||
|
|
||||||
Model.knex(db);
|
Model.knex(db());
|
||||||
|
|
||||||
class AccessListAuth extends Model {
|
class AccessListAuth extends Model {
|
||||||
$beforeInsert() {
|
$beforeInsert() {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import db from "../db.js";
|
|||||||
import accessListModel from "./access_list.js";
|
import accessListModel from "./access_list.js";
|
||||||
import now from "./now_helper.js";
|
import now from "./now_helper.js";
|
||||||
|
|
||||||
Model.knex(db);
|
Model.knex(db());
|
||||||
|
|
||||||
class AccessListClient extends Model {
|
class AccessListClient extends Model {
|
||||||
$beforeInsert() {
|
$beforeInsert() {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import db from "../db.js";
|
|||||||
import now from "./now_helper.js";
|
import now from "./now_helper.js";
|
||||||
import User from "./user.js";
|
import User from "./user.js";
|
||||||
|
|
||||||
Model.knex(db);
|
Model.knex(db());
|
||||||
|
|
||||||
class AuditLog extends Model {
|
class AuditLog extends Model {
|
||||||
$beforeInsert() {
|
$beforeInsert() {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { convertBoolFieldsToInt, convertIntFieldsToBool } from "../lib/helpers.j
|
|||||||
import now from "./now_helper.js";
|
import now from "./now_helper.js";
|
||||||
import User from "./user.js";
|
import User from "./user.js";
|
||||||
|
|
||||||
Model.knex(db);
|
Model.knex(db());
|
||||||
|
|
||||||
const boolFields = ["is_deleted"];
|
const boolFields = ["is_deleted"];
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import redirectionHostModel from "./redirection_host.js";
|
|||||||
import streamModel from "./stream.js";
|
import streamModel from "./stream.js";
|
||||||
import userModel from "./user.js";
|
import userModel from "./user.js";
|
||||||
|
|
||||||
Model.knex(db);
|
Model.knex(db());
|
||||||
|
|
||||||
const boolFields = ["is_deleted"];
|
const boolFields = ["is_deleted"];
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import Certificate from "./certificate.js";
|
|||||||
import now from "./now_helper.js";
|
import now from "./now_helper.js";
|
||||||
import User from "./user.js";
|
import User from "./user.js";
|
||||||
|
|
||||||
Model.knex(db);
|
Model.knex(db());
|
||||||
|
|
||||||
const boolFields = ["is_deleted", "ssl_forced", "http2_support", "enabled", "hsts_enabled", "hsts_subdomains"];
|
const boolFields = ["is_deleted", "ssl_forced", "http2_support", "enabled", "hsts_enabled", "hsts_subdomains"];
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Model } from "objection";
|
|||||||
import db from "../db.js";
|
import db from "../db.js";
|
||||||
import { isSqlite } from "../lib/config.js";
|
import { isSqlite } from "../lib/config.js";
|
||||||
|
|
||||||
Model.knex(db);
|
Model.knex(db());
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
if (isSqlite()) {
|
if (isSqlite()) {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import Certificate from "./certificate.js";
|
|||||||
import now from "./now_helper.js";
|
import now from "./now_helper.js";
|
||||||
import User from "./user.js";
|
import User from "./user.js";
|
||||||
|
|
||||||
Model.knex(db);
|
Model.knex(db());
|
||||||
|
|
||||||
const boolFields = [
|
const boolFields = [
|
||||||
"is_deleted",
|
"is_deleted",
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import Certificate from "./certificate.js";
|
|||||||
import now from "./now_helper.js";
|
import now from "./now_helper.js";
|
||||||
import User from "./user.js";
|
import User from "./user.js";
|
||||||
|
|
||||||
Model.knex(db);
|
Model.knex(db());
|
||||||
|
|
||||||
const boolFields = [
|
const boolFields = [
|
||||||
"is_deleted",
|
"is_deleted",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
import { Model } from "objection";
|
import { Model } from "objection";
|
||||||
import db from "../db.js";
|
import db from "../db.js";
|
||||||
|
|
||||||
Model.knex(db);
|
Model.knex(db());
|
||||||
|
|
||||||
class Setting extends Model {
|
class Setting extends Model {
|
||||||
$beforeInsert () {
|
$beforeInsert () {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import Certificate from "./certificate.js";
|
|||||||
import now from "./now_helper.js";
|
import now from "./now_helper.js";
|
||||||
import User from "./user.js";
|
import User from "./user.js";
|
||||||
|
|
||||||
Model.knex(db);
|
Model.knex(db());
|
||||||
|
|
||||||
const boolFields = ["is_deleted", "enabled", "tcp_forwarding", "udp_forwarding"];
|
const boolFields = ["is_deleted", "enabled", "tcp_forwarding", "udp_forwarding"];
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { convertBoolFieldsToInt, convertIntFieldsToBool } from "../lib/helpers.j
|
|||||||
import now from "./now_helper.js";
|
import now from "./now_helper.js";
|
||||||
import UserPermission from "./user_permission.js";
|
import UserPermission from "./user_permission.js";
|
||||||
|
|
||||||
Model.knex(db);
|
Model.knex(db());
|
||||||
|
|
||||||
const boolFields = ["is_deleted", "is_disabled"];
|
const boolFields = ["is_deleted", "is_disabled"];
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { Model } from "objection";
|
|||||||
import db from "../db.js";
|
import db from "../db.js";
|
||||||
import now from "./now_helper.js";
|
import now from "./now_helper.js";
|
||||||
|
|
||||||
Model.knex(db);
|
Model.knex(db());
|
||||||
|
|
||||||
class UserPermission extends Model {
|
class UserPermission extends Model {
|
||||||
$beforeInsert () {
|
$beforeInsert () {
|
||||||
|
|||||||
Reference in New Issue
Block a user