ci: add golangci-lint config and fix formatting

- Add .golangci.yml with minimal linters (govet, ineffassign)
- Run gofmt -s and goimports on all files to fix formatting
- Disable fieldalignment and copylocks checks in govet
This commit is contained in:
2025-12-11 17:53:28 +01:00
parent 6b66ae5429
commit 914307ac8f
89 changed files with 1516 additions and 1618 deletions

View File

@@ -23,21 +23,21 @@ func ParsePostgreSQLVersion(versionStr string) (*VersionInfo, error) {
// Match patterns like "PostgreSQL 17.7", "PostgreSQL 13.11", "PostgreSQL 10.23"
re := regexp.MustCompile(`PostgreSQL\s+(\d+)\.(\d+)`)
matches := re.FindStringSubmatch(versionStr)
if len(matches) < 3 {
return nil, fmt.Errorf("could not parse PostgreSQL version from: %s", versionStr)
}
major, err := strconv.Atoi(matches[1])
if err != nil {
return nil, fmt.Errorf("invalid major version: %s", matches[1])
}
minor, err := strconv.Atoi(matches[2])
if err != nil {
return nil, fmt.Errorf("invalid minor version: %s", matches[2])
}
return &VersionInfo{
Major: major,
Minor: minor,
@@ -53,24 +53,24 @@ func GetDumpFileVersion(dumpPath string) (*VersionInfo, error) {
if err != nil {
return nil, fmt.Errorf("failed to read dump file metadata: %w (output: %s)", err, string(output))
}
// Look for "Dumped from database version: X.Y.Z" in output
re := regexp.MustCompile(`Dumped from database version:\s+(\d+)\.(\d+)`)
matches := re.FindStringSubmatch(string(output))
if len(matches) < 3 {
// Try alternate format in some dumps
re = regexp.MustCompile(`PostgreSQL database dump.*(\d+)\.(\d+)`)
matches = re.FindStringSubmatch(string(output))
}
if len(matches) < 3 {
return nil, fmt.Errorf("could not find version information in dump file")
}
major, _ := strconv.Atoi(matches[1])
minor, _ := strconv.Atoi(matches[2])
return &VersionInfo{
Major: major,
Minor: minor,
@@ -81,18 +81,18 @@ func GetDumpFileVersion(dumpPath string) (*VersionInfo, error) {
// CheckVersionCompatibility checks if restoring from source version to target version is safe
func CheckVersionCompatibility(sourceVer, targetVer *VersionInfo) *VersionCompatibilityResult {
result := &VersionCompatibilityResult{
Compatible: true,
Compatible: true,
SourceVersion: sourceVer,
TargetVersion: targetVer,
}
// Same major version - always compatible
if sourceVer.Major == targetVer.Major {
result.Level = CompatibilityLevelSafe
result.Message = "Same major version - fully compatible"
return result
}
// Downgrade - not supported
if sourceVer.Major > targetVer.Major {
result.Compatible = false
@@ -101,10 +101,10 @@ func CheckVersionCompatibility(sourceVer, targetVer *VersionInfo) *VersionCompat
result.Warnings = append(result.Warnings, "Database downgrades require pg_dump from the target version")
return result
}
// Upgrade - check how many major versions
versionDiff := targetVer.Major - sourceVer.Major
if versionDiff == 1 {
// One major version upgrade - generally safe
result.Level = CompatibilityLevelSafe
@@ -113,7 +113,7 @@ func CheckVersionCompatibility(sourceVer, targetVer *VersionInfo) *VersionCompat
// 2-3 major versions - should work but review release notes
result.Level = CompatibilityLevelWarning
result.Message = fmt.Sprintf("Upgrading from PostgreSQL %d to %d - supported but review release notes", sourceVer.Major, targetVer.Major)
result.Warnings = append(result.Warnings,
result.Warnings = append(result.Warnings,
fmt.Sprintf("You are jumping %d major versions - some features may have changed", versionDiff))
result.Warnings = append(result.Warnings,
"Review release notes for deprecated features or behavior changes")
@@ -134,13 +134,13 @@ func CheckVersionCompatibility(sourceVer, targetVer *VersionInfo) *VersionCompat
result.Recommendations = append(result.Recommendations,
"Review PostgreSQL release notes for versions "+strconv.Itoa(sourceVer.Major)+" through "+strconv.Itoa(targetVer.Major))
}
// Add general upgrade advice
if versionDiff > 0 {
result.Recommendations = append(result.Recommendations,
"Run ANALYZE on all tables after restore for optimal query performance")
}
return result
}
@@ -189,33 +189,33 @@ func (e *Engine) CheckRestoreVersionCompatibility(ctx context.Context, dumpPath
e.log.Warn("Could not determine dump file version", "error", err)
return nil, nil
}
// Get target database version
targetVerStr, err := e.db.GetVersion(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get target database version: %w", err)
}
targetVer, err := ParsePostgreSQLVersion(targetVerStr)
if err != nil {
return nil, fmt.Errorf("failed to parse target version: %w", err)
}
// Check compatibility
result := CheckVersionCompatibility(dumpVer, targetVer)
// Log the results
e.log.Info("Version compatibility check",
"source", dumpVer.Full,
"target", targetVer.Full,
"level", result.Level.String())
if len(result.Warnings) > 0 {
for _, warning := range result.Warnings {
e.log.Warn(warning)
}
}
return result, nil
}