9c58fe2312
A fresh production environment only ran migrations, so the four built-in platform templates were never inserted unless someone manually ran dev-seed (which also writes broad demo data). Extract the platform template upsert into a reusable repository.EnsurePlatformTemplates and add a standalone cmd/seed-platform-templates that calls it. Bake the binary into the migrate image and chain it after migrate up in both docker-compose and the k3s migration job (mounting app config so the binary can dial the right database). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
|
|
"github.com/geo-platform/tenant-api/internal/shared/config"
|
|
"github.com/geo-platform/tenant-api/internal/tenant/prompts"
|
|
"github.com/geo-platform/tenant-api/internal/tenant/repository"
|
|
)
|
|
|
|
func main() {
|
|
configPath := "configs/config.yaml"
|
|
if p := strings.TrimSpace(os.Getenv("CONFIG_PATH")); p != "" {
|
|
configPath = p
|
|
}
|
|
|
|
cfg, err := config.Load(configPath)
|
|
if err != nil {
|
|
log.Fatalf("load config: %v", err)
|
|
}
|
|
if password := strings.TrimSpace(os.Getenv("POSTGRES_PASSWORD")); password != "" {
|
|
cfg.Database.Password = password
|
|
}
|
|
prompts.SetConfigFile(filepath.Join(filepath.Dir(configPath), "prompts.yml"))
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
|
defer cancel()
|
|
|
|
pool, err := pgxpool.New(ctx, cfg.Database.DSN())
|
|
if err != nil {
|
|
log.Fatalf("connect database: %v", err)
|
|
}
|
|
defer pool.Close()
|
|
|
|
tx, err := pool.Begin(ctx)
|
|
if err != nil {
|
|
log.Fatalf("begin transaction: %v", err)
|
|
}
|
|
defer func() {
|
|
_ = tx.Rollback(ctx)
|
|
}()
|
|
|
|
count, err := repository.EnsurePlatformTemplates(ctx, tx)
|
|
if err != nil {
|
|
log.Fatalf("ensure platform templates: %v", err)
|
|
}
|
|
if err := tx.Commit(ctx); err != nil {
|
|
log.Fatalf("commit platform templates: %v", err)
|
|
}
|
|
|
|
fmt.Printf("Platform templates ensured: %d\n", count)
|
|
}
|