mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-08-28 19:40:28 +00:00
Rejig embedded assets to a central folder
This commit is contained in:
@@ -2,7 +2,6 @@ package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"embed"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"path"
|
||||
@@ -11,15 +10,13 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"npm/embed"
|
||||
"npm/internal/logger"
|
||||
"npm/internal/util"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
//go:embed migrations/*.sql
|
||||
var migrationFiles embed.FS
|
||||
|
||||
// MigrationConfiguration options for the migrator.
|
||||
type MigrationConfiguration struct {
|
||||
Table string `json:"table"`
|
||||
@@ -100,7 +97,7 @@ func createMigrationTable(db *sqlx.DB) error {
|
||||
|
||||
// tableExists will check the database for the existence of the specified table.
|
||||
func tableExists(db *sqlx.DB, tableName string) bool {
|
||||
query := `SELECT name FROM sqlite_master WHERE type='table' AND name = $1`
|
||||
query := `SELECT CASE name WHEN $1 THEN true ELSE false END AS found FROM sqlite_master WHERE type='table' AND name = $1`
|
||||
|
||||
row := db.QueryRowx(query, tableName)
|
||||
if row == nil {
|
||||
@@ -131,7 +128,7 @@ func performFileMigrations(db *sqlx.DB) (int, error) {
|
||||
}
|
||||
|
||||
// List up the ".sql" files on disk
|
||||
err := fs.WalkDir(migrationFiles, ".", func(file string, d fs.DirEntry, err error) error {
|
||||
err := fs.WalkDir(embed.MigrationFiles, ".", func(file string, d fs.DirEntry, err error) error {
|
||||
if !d.IsDir() {
|
||||
shortFile := filepath.Base(file)
|
||||
|
||||
@@ -143,7 +140,7 @@ func performFileMigrations(db *sqlx.DB) (int, error) {
|
||||
|
||||
logger.Info("Migration: Importing %v", shortFile)
|
||||
|
||||
sqlContents, ioErr := migrationFiles.ReadFile(path.Clean(file))
|
||||
sqlContents, ioErr := embed.MigrationFiles.ReadFile(path.Clean(file))
|
||||
if ioErr != nil {
|
||||
return ioErr
|
||||
}
|
||||
|
Reference in New Issue
Block a user