mirror of
https://github.com/jc21/nginx-proxy-manager.git
synced 2024-08-30 18:22:48 +00:00
Updates
This commit is contained in:
parent
94b6971ef7
commit
4b4c7baea4
@ -139,7 +139,7 @@ CREATE TABLE "upstream" (
|
|||||||
"created_at" BIGINT NOT NULL DEFAULT 0,
|
"created_at" BIGINT NOT NULL DEFAULT 0,
|
||||||
"updated_at" BIGINT NOT NULL DEFAULT 0,
|
"updated_at" BIGINT NOT NULL DEFAULT 0,
|
||||||
"is_deleted" INTEGER NOT NULL DEFAULT 0, -- int on purpose, gormism
|
"is_deleted" INTEGER NOT NULL DEFAULT 0, -- int on purpose, gormism
|
||||||
"user_id" INTEGER NOT NULL REFERENCES "user"("id"),
|
"user_id" INTEGER NOT NULL REFERENCES "user"("id") ON DELETE CASCADE,
|
||||||
"name" VARCHAR(50) NOT NULL,
|
"name" VARCHAR(50) NOT NULL,
|
||||||
"nginx_template_id" INTEGER NOT NULL REFERENCES "nginx_template"("id") ON DELETE CASCADE,
|
"nginx_template_id" INTEGER NOT NULL REFERENCES "nginx_template"("id") ON DELETE CASCADE,
|
||||||
"ip_hash" BOOLEAN NOT NULL DEFAULT FALSE,
|
"ip_hash" BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
@ -1,8 +1,27 @@
|
|||||||
package database
|
package database
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"npm/internal/config"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// DateFormat for DateFormat
|
// DateFormat for DateFormat
|
||||||
DateFormat = "2006-01-02"
|
DateFormat = "2006-01-02"
|
||||||
// DateTimeFormat for DateTimeFormat
|
// DateTimeFormat for DateTimeFormat
|
||||||
DateTimeFormat = "2006-01-02T15:04:05"
|
DateTimeFormat = "2006-01-02T15:04:05"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// QuoteTableName is a special function that will quote a table
|
||||||
|
// name based on the driver. Gorm normally handles this but this
|
||||||
|
// is for special cases where we run raw sql
|
||||||
|
func QuoteTableName(tbl string) string {
|
||||||
|
switch strings.ToLower(config.Configuration.DB.Driver) {
|
||||||
|
case config.DatabasePostgres:
|
||||||
|
return fmt.Sprintf(`"%s"`, tbl)
|
||||||
|
default:
|
||||||
|
// This is the same for Mysql and Sqlite
|
||||||
|
return fmt.Sprintf("`%s`", tbl)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -21,7 +21,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter) (entity.ListResponse,
|
|||||||
Direction: "ASC",
|
Direction: "ASC",
|
||||||
}
|
}
|
||||||
|
|
||||||
dbo := entity.ListQueryBuilder(&pageInfo, defaultSort, filters, entity.GetFilterMap(Model{}, true))
|
dbo := entity.ListQueryBuilder(&pageInfo, filters, entity.GetFilterMap(Model{}, true))
|
||||||
|
|
||||||
// Get count of items in this search
|
// Get count of items in this search
|
||||||
var totalRows int64
|
var totalRows int64
|
||||||
@ -31,7 +31,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter) (entity.ListResponse,
|
|||||||
|
|
||||||
// Get rows
|
// Get rows
|
||||||
items := make([]Model, 0)
|
items := make([]Model, 0)
|
||||||
if res := dbo.Find(&items); res.Error != nil {
|
if res := entity.AddOrderToList(dbo, &pageInfo, defaultSort).Find(&items); res.Error != nil {
|
||||||
return result, res.Error
|
return result, res.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter, expand []string) (ent
|
|||||||
Direction: "ASC",
|
Direction: "ASC",
|
||||||
}
|
}
|
||||||
|
|
||||||
dbo := entity.ListQueryBuilder(&pageInfo, defaultSort, filters, entity.GetFilterMap(Model{}, true))
|
dbo := entity.ListQueryBuilder(&pageInfo, filters, entity.GetFilterMap(Model{}, true))
|
||||||
|
|
||||||
// Get count of items in this search
|
// Get count of items in this search
|
||||||
var totalRows int64
|
var totalRows int64
|
||||||
@ -47,7 +47,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter, expand []string) (ent
|
|||||||
|
|
||||||
// Get rows
|
// Get rows
|
||||||
items := make([]Model, 0)
|
items := make([]Model, 0)
|
||||||
if res := dbo.Find(&items); res.Error != nil {
|
if res := entity.AddOrderToList(dbo, &pageInfo, defaultSort).Find(&items); res.Error != nil {
|
||||||
return result, res.Error
|
return result, res.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter) (entity.ListResponse,
|
|||||||
Direction: "ASC",
|
Direction: "ASC",
|
||||||
}
|
}
|
||||||
|
|
||||||
dbo := entity.ListQueryBuilder(&pageInfo, defaultSort, filters, entity.GetFilterMap(Model{}, true))
|
dbo := entity.ListQueryBuilder(&pageInfo, filters, entity.GetFilterMap(Model{}, true))
|
||||||
|
|
||||||
// Get count of items in this search
|
// Get count of items in this search
|
||||||
var totalRows int64
|
var totalRows int64
|
||||||
@ -31,7 +31,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter) (entity.ListResponse,
|
|||||||
|
|
||||||
// Get rows
|
// Get rows
|
||||||
items := make([]Model, 0)
|
items := make([]Model, 0)
|
||||||
if res := dbo.Find(&items); res.Error != nil {
|
if res := entity.AddOrderToList(dbo, &pageInfo, defaultSort).Find(&items); res.Error != nil {
|
||||||
return result, res.Error
|
return result, res.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter) (entity.ListResponse,
|
|||||||
Direction: "ASC",
|
Direction: "ASC",
|
||||||
}
|
}
|
||||||
|
|
||||||
dbo := entity.ListQueryBuilder(&pageInfo, defaultSort, filters, entity.GetFilterMap(Model{}, true))
|
dbo := entity.ListQueryBuilder(&pageInfo, filters, entity.GetFilterMap(Model{}, true))
|
||||||
|
|
||||||
// Get count of items in this search
|
// Get count of items in this search
|
||||||
var totalRows int64
|
var totalRows int64
|
||||||
@ -31,7 +31,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter) (entity.ListResponse,
|
|||||||
|
|
||||||
// Get rows
|
// Get rows
|
||||||
items := make([]Model, 0)
|
items := make([]Model, 0)
|
||||||
if res := dbo.Find(&items); res.Error != nil {
|
if res := entity.AddOrderToList(dbo, &pageInfo, defaultSort).Find(&items); res.Error != nil {
|
||||||
return result, res.Error
|
return result, res.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter, expand []string) (ent
|
|||||||
Direction: "ASC",
|
Direction: "ASC",
|
||||||
}
|
}
|
||||||
|
|
||||||
dbo := entity.ListQueryBuilder(&pageInfo, defaultSort, filters, entity.GetFilterMap(Model{}, true))
|
dbo := entity.ListQueryBuilder(&pageInfo, filters, entity.GetFilterMap(Model{}, true))
|
||||||
|
|
||||||
// Get count of items in this search
|
// Get count of items in this search
|
||||||
var totalRows int64
|
var totalRows int64
|
||||||
@ -33,7 +33,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter, expand []string) (ent
|
|||||||
|
|
||||||
// Get rows
|
// Get rows
|
||||||
items := make([]Model, 0)
|
items := make([]Model, 0)
|
||||||
if res := dbo.Find(&items); res.Error != nil {
|
if res := entity.AddOrderToList(dbo, &pageInfo, defaultSort).Find(&items); res.Error != nil {
|
||||||
return result, res.Error
|
return result, res.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,13 +25,21 @@ type ListResponse struct {
|
|||||||
// ListQueryBuilder is used to setup queries for lists
|
// ListQueryBuilder is used to setup queries for lists
|
||||||
func ListQueryBuilder(
|
func ListQueryBuilder(
|
||||||
pageInfo *model.PageInfo,
|
pageInfo *model.PageInfo,
|
||||||
defaultSort model.Sort,
|
|
||||||
filters []model.Filter,
|
filters []model.Filter,
|
||||||
filterMap map[string]filterMapValue,
|
filterMap map[string]filterMapValue,
|
||||||
) *gorm.DB {
|
) *gorm.DB {
|
||||||
scopes := make([]func(*gorm.DB) *gorm.DB, 0)
|
scopes := make([]func(*gorm.DB) *gorm.DB, 0)
|
||||||
scopes = append(scopes, ScopeOrderBy(pageInfo, defaultSort))
|
|
||||||
scopes = append(scopes, ScopeOffsetLimit(pageInfo))
|
scopes = append(scopes, ScopeOffsetLimit(pageInfo))
|
||||||
scopes = append(scopes, ScopeFilters(filters, filterMap))
|
scopes = append(scopes, ScopeFilters(filters, filterMap))
|
||||||
return database.GetDB().Scopes(scopes...)
|
return database.GetDB().Scopes(scopes...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddOrderToList is used after query above is used for counting
|
||||||
|
// Postgres in particular doesn't like count(*) when ordering at the same time
|
||||||
|
func AddOrderToList(
|
||||||
|
dbo *gorm.DB,
|
||||||
|
pageInfo *model.PageInfo,
|
||||||
|
defaultSort model.Sort,
|
||||||
|
) *gorm.DB {
|
||||||
|
return dbo.Scopes(ScopeOrderBy(pageInfo, defaultSort))
|
||||||
|
}
|
||||||
|
@ -21,7 +21,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter) (entity.ListResponse,
|
|||||||
Direction: "ASC",
|
Direction: "ASC",
|
||||||
}
|
}
|
||||||
|
|
||||||
dbo := entity.ListQueryBuilder(&pageInfo, defaultSort, filters, entity.GetFilterMap(Model{}, true))
|
dbo := entity.ListQueryBuilder(&pageInfo, filters, entity.GetFilterMap(Model{}, true))
|
||||||
|
|
||||||
// Get count of items in this search
|
// Get count of items in this search
|
||||||
var totalRows int64
|
var totalRows int64
|
||||||
@ -31,7 +31,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter) (entity.ListResponse,
|
|||||||
|
|
||||||
// Get rows
|
// Get rows
|
||||||
items := make([]Model, 0)
|
items := make([]Model, 0)
|
||||||
if res := dbo.Find(&items); res.Error != nil {
|
if res := entity.AddOrderToList(dbo, &pageInfo, defaultSort).Find(&items); res.Error != nil {
|
||||||
return result, res.Error
|
return result, res.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter) (entity.ListResponse,
|
|||||||
Direction: "ASC",
|
Direction: "ASC",
|
||||||
}
|
}
|
||||||
|
|
||||||
dbo := entity.ListQueryBuilder(&pageInfo, defaultSort, filters, entity.GetFilterMap(Model{}, true))
|
dbo := entity.ListQueryBuilder(&pageInfo, filters, entity.GetFilterMap(Model{}, true))
|
||||||
|
|
||||||
// Get count of items in this search
|
// Get count of items in this search
|
||||||
var totalRows int64
|
var totalRows int64
|
||||||
@ -40,7 +40,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter) (entity.ListResponse,
|
|||||||
|
|
||||||
// Get rows
|
// Get rows
|
||||||
items := make([]Model, 0)
|
items := make([]Model, 0)
|
||||||
if res := dbo.Find(&items); res.Error != nil {
|
if res := entity.AddOrderToList(dbo, &pageInfo, defaultSort).Find(&items); res.Error != nil {
|
||||||
return result, res.Error
|
return result, res.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter) (entity.ListResponse,
|
|||||||
Direction: "ASC",
|
Direction: "ASC",
|
||||||
}
|
}
|
||||||
|
|
||||||
dbo := entity.ListQueryBuilder(&pageInfo, defaultSort, filters, entity.GetFilterMap(Model{}, true))
|
dbo := entity.ListQueryBuilder(&pageInfo, filters, entity.GetFilterMap(Model{}, true))
|
||||||
|
|
||||||
// Get count of items in this search
|
// Get count of items in this search
|
||||||
var totalRows int64
|
var totalRows int64
|
||||||
@ -31,7 +31,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter) (entity.ListResponse,
|
|||||||
|
|
||||||
// Get rows
|
// Get rows
|
||||||
items := make([]Model, 0)
|
items := make([]Model, 0)
|
||||||
if res := dbo.Find(&items); res.Error != nil {
|
if res := entity.AddOrderToList(dbo, &pageInfo, defaultSort).Find(&items); res.Error != nil {
|
||||||
return result, res.Error
|
return result, res.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter, expand []string) (ent
|
|||||||
Direction: "ASC",
|
Direction: "ASC",
|
||||||
}
|
}
|
||||||
|
|
||||||
dbo := entity.ListQueryBuilder(&pageInfo, defaultSort, filters, entity.GetFilterMap(Model{}, true))
|
dbo := entity.ListQueryBuilder(&pageInfo, filters, entity.GetFilterMap(Model{}, true))
|
||||||
|
|
||||||
// Get count of items in this search
|
// Get count of items in this search
|
||||||
var totalRows int64
|
var totalRows int64
|
||||||
@ -31,7 +31,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter, expand []string) (ent
|
|||||||
|
|
||||||
// Get rows
|
// Get rows
|
||||||
items := make([]Model, 0)
|
items := make([]Model, 0)
|
||||||
if res := dbo.Find(&items); res.Error != nil {
|
if res := entity.AddOrderToList(dbo, &pageInfo, defaultSort).Find(&items); res.Error != nil {
|
||||||
return result, res.Error
|
return result, res.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter) (entity.ListResponse,
|
|||||||
Direction: "ASC",
|
Direction: "ASC",
|
||||||
}
|
}
|
||||||
|
|
||||||
dbo := entity.ListQueryBuilder(&pageInfo, defaultSort, filters, entity.GetFilterMap(Model{}, true))
|
dbo := entity.ListQueryBuilder(&pageInfo, filters, entity.GetFilterMap(Model{}, true))
|
||||||
|
|
||||||
// Get count of items in this search
|
// Get count of items in this search
|
||||||
var totalRows int64
|
var totalRows int64
|
||||||
@ -40,7 +40,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter) (entity.ListResponse,
|
|||||||
|
|
||||||
// Get rows
|
// Get rows
|
||||||
items := make([]Model, 0)
|
items := make([]Model, 0)
|
||||||
if res := dbo.Find(&items); res.Error != nil {
|
if res := entity.AddOrderToList(dbo, &pageInfo, defaultSort).Find(&items); res.Error != nil {
|
||||||
return result, res.Error
|
return result, res.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package user
|
package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"npm/internal/database"
|
"npm/internal/database"
|
||||||
"npm/internal/entity"
|
"npm/internal/entity"
|
||||||
"npm/internal/logger"
|
"npm/internal/logger"
|
||||||
@ -41,7 +42,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter, expand []string) (ent
|
|||||||
Direction: "ASC",
|
Direction: "ASC",
|
||||||
}
|
}
|
||||||
|
|
||||||
dbo := entity.ListQueryBuilder(&pageInfo, defaultSort, filters, entity.GetFilterMap(Model{}, true))
|
dbo := entity.ListQueryBuilder(&pageInfo, filters, entity.GetFilterMap(Model{}, true))
|
||||||
|
|
||||||
// Get count of items in this search
|
// Get count of items in this search
|
||||||
var totalRows int64
|
var totalRows int64
|
||||||
@ -51,7 +52,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter, expand []string) (ent
|
|||||||
|
|
||||||
// Get rows
|
// Get rows
|
||||||
items := make([]Model, 0)
|
items := make([]Model, 0)
|
||||||
if res := dbo.Find(&items); res.Error != nil {
|
if res := entity.AddOrderToList(dbo, &pageInfo, defaultSort).Find(&items); res.Error != nil {
|
||||||
return result, res.Error
|
return result, res.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,8 +85,7 @@ func List(pageInfo model.PageInfo, filters []model.Filter, expand []string) (ent
|
|||||||
func DeleteAll() error {
|
func DeleteAll() error {
|
||||||
db := database.GetDB()
|
db := database.GetDB()
|
||||||
// nolint errcheck
|
// nolint errcheck
|
||||||
db.Exec("DELETE FROM auth")
|
result := db.Exec(fmt.Sprintf(`DELETE FROM %s WHERE is_system = ?`, database.QuoteTableName("user")), false)
|
||||||
result := db.Exec("DELETE FROM user WHERE is_system = ?", false)
|
|
||||||
return result.Error
|
return result.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user