fix: PHP versions fallback and auto-migrate on panel start

This commit is contained in:
orohi
2026-06-17 05:45:22 +03:00
parent f94143acf0
commit 52c4c785df
7 changed files with 54 additions and 32 deletions
+12 -15
View File
@@ -8,6 +8,7 @@ import (
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/panelhosting/panel/internal/models"
"github.com/panelhosting/panel/internal/phpversions"
)
type SiteRepository struct {
@@ -121,10 +122,7 @@ func (r *PHPVersionRepository) ListActive(ctx context.Context) ([]string, error)
SELECT version FROM php_versions WHERE is_active = true ORDER BY sort_order
`)
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return defaultPHPVersions(), nil
}
return nil, err
return phpversions.Defaults, nil
}
defer rows.Close()
@@ -132,25 +130,24 @@ func (r *PHPVersionRepository) ListActive(ctx context.Context) ([]string, error)
for rows.Next() {
var v string
if err := rows.Scan(&v); err != nil {
return nil, err
return phpversions.Defaults, nil
}
versions = append(versions, v)
}
if len(versions) == 0 {
return defaultPHPVersions(), nil
if err := rows.Err(); err != nil || len(versions) == 0 {
return phpversions.Defaults, nil
}
return versions, rows.Err()
return versions, nil
}
func (r *PHPVersionRepository) IsActive(ctx context.Context, version string) (bool, error) {
var active bool
err := r.pool.QueryRow(ctx, `SELECT is_active FROM php_versions WHERE version = $1`, version).Scan(&active)
if errors.Is(err, pgx.ErrNoRows) {
return false, nil
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return phpversions.Contains(version), nil
}
return phpversions.Contains(version), nil
}
return active, err
}
func defaultPHPVersions() []string {
return []string{"8.1", "8.2", "8.3", "8.4"}
return active, nil
}