42 lines
977 B
Go
42 lines
977 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab3/internal/config"
|
|
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab3/internal/store/postgres"
|
|
|
|
"go.uber.org/fx"
|
|
)
|
|
|
|
// run dispatches the server command or the container healthcheck.
|
|
func run(args []string) error {
|
|
if len(args) == 0 {
|
|
fx.New(CreateApp()).Run()
|
|
return nil
|
|
}
|
|
if len(args) == 1 && args[0] == "migrate" {
|
|
return migrate()
|
|
}
|
|
if len(args) == 1 && args[0] == "healthcheck" {
|
|
return healthcheck()
|
|
}
|
|
return fmt.Errorf("usage: server [healthcheck|migrate]")
|
|
}
|
|
|
|
// migrate applies versioned DDL once from an operator job, independently of the API.
|
|
func migrate() error {
|
|
cfg, err := config.NewPersistence()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
database, err := postgres.New(postgres.Options{URL: cfg.DatabaseURL, MaxConnections: 1, Timeout: 30 * time.Second})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer database.Close()
|
|
return database.Start(context.Background())
|
|
}
|