2
0
Files
gitcaddy-server/models/ai/seed.go
logikonline 12f4ea03a8
Some checks failed
Build and Release / Create Release (push) Successful in 0s
Trigger Vault Plugin Rebuild / Trigger Vault Rebuild (push) Successful in 0s
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 2m48s
Build and Release / Lint (push) Failing after 5m2s
Build and Release / Build Binaries (amd64, windows, windows-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, linux, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, linux, linux-latest) (push) Has been skipped
Build and Release / Unit Tests (push) Successful in 5m37s
refactor: add /v3 suffix to module path for proper Go semver
Go's semantic import versioning requires v2+ modules to include the
major version in the module path. This enables using proper version
tags (v3.x.x) instead of pseudo-versions.

Updated module path: code.gitcaddy.com/server/v3
2026-01-17 17:53:59 -05:00

75 lines
2.0 KiB
Go

// Copyright 2026 MarketAlly. All rights reserved.
// SPDX-License-Identifier: MIT
package ai
import (
"context"
"code.gitcaddy.com/server/v3/modules/json"
"code.gitcaddy.com/server/v3/models/db"
"code.gitcaddy.com/server/v3/modules/log"
"code.gitcaddy.com/server/v3/modules/options"
)
// SeedData represents the structure of the seed JSON file
type SeedData struct {
Patterns []struct {
Pattern string `json:"pattern"`
RunnerType string `json:"runner_type"`
ProjectType string `json:"project_type"`
Framework string `json:"framework"`
ErrorMessage string `json:"error_message"`
Diagnosis string `json:"diagnosis"`
Solution string `json:"solution"`
} `json:"patterns"`
}
// SeedErrorPatternsIfEmpty seeds error patterns from the seed file if the table is empty
func SeedErrorPatternsIfEmpty(ctx context.Context) error {
count, err := db.GetEngine(ctx).Count(&ErrorPattern{})
if err != nil {
return err
}
if count > 0 {
log.Debug("Error patterns table already has %d entries, skipping seed", count)
return nil
}
log.Info("Seeding error patterns from seed file...")
// Load seed data from embedded options
data, err := options.AssetFS().ReadFile("seed/error_patterns.json")
if err != nil {
log.Warn("Could not read error patterns seed file: %v", err)
return nil // Not an error, just no seed file
}
var seedData SeedData
if err := json.Unmarshal(data, &seedData); err != nil {
log.Error("Failed to parse error patterns seed file: %v", err)
return err
}
return db.WithTx(ctx, func(ctx context.Context) error {
for _, p := range seedData.Patterns {
ep := &ErrorPattern{
Pattern: p.Pattern,
RunnerType: p.RunnerType,
ProjectType: p.ProjectType,
Framework: p.Framework,
ErrorMessage: p.ErrorMessage,
Diagnosis: p.Diagnosis,
Solution: p.Solution,
}
if err := db.Insert(ctx, ep); err != nil {
return err
}
}
log.Info("Seeded %d error patterns", len(seedData.Patterns))
return nil
})
}