mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-21 23:22:34 +01:00
fix(setup): reduce friction in installation procedure
- Add Language default ("jp") so missing field no longer produces empty
string, and include language selector in setup wizard
- Add --setup flag to re-run wizard even when config.json exists,
providing a recovery path for corrupted configs
- Auto-apply seed data on fresh databases so users who skip the wizard
still get shops, events, and gacha
- Fix stale docs referencing non-existent init/setup.sh and
schemas/patch-schema/ in docker/README, CONTRIBUTING, and README
This commit is contained in:
24
main.go
24
main.go
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
cfg "erupe-ce/config"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
@@ -71,6 +72,9 @@ func setupDiscordBot(config *cfg.Config, logger *zap.Logger) *discordbot.Discord
|
||||
}
|
||||
|
||||
func main() {
|
||||
runSetup := flag.Bool("setup", false, "Launch the setup wizard (even if config.json exists)")
|
||||
flag.Parse()
|
||||
|
||||
var err error
|
||||
|
||||
var zapLogger *zap.Logger
|
||||
@@ -79,6 +83,13 @@ func main() {
|
||||
defer func() { _ = zapLogger.Sync() }()
|
||||
logger := zapLogger.Named("main")
|
||||
|
||||
if *runSetup {
|
||||
logger.Info("Launching setup wizard (--setup)")
|
||||
if err := setup.Run(logger.Named("setup"), 8080); err != nil {
|
||||
logger.Fatal("Setup wizard failed", zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
||||
config, cfgErr := cfg.LoadConfig()
|
||||
if cfgErr != nil {
|
||||
if _, err := os.Stat("config.json"); os.IsNotExist(err) {
|
||||
@@ -156,6 +167,7 @@ func main() {
|
||||
logger.Info("Database: Started successfully")
|
||||
|
||||
// Run database migrations
|
||||
verBefore, _ := migrations.Version(db)
|
||||
applied, migErr := migrations.Migrate(db, logger.Named("migrations"))
|
||||
if migErr != nil {
|
||||
preventClose(config, fmt.Sprintf("Database migration failed: %s", migErr.Error()))
|
||||
@@ -165,6 +177,18 @@ func main() {
|
||||
logger.Info(fmt.Sprintf("Database: Applied %d migration(s), now at version %d", applied, ver))
|
||||
}
|
||||
|
||||
// Auto-apply seed data on a fresh database so users who skip the wizard
|
||||
// still get shops, events, and gacha. Seed files use ON CONFLICT DO NOTHING
|
||||
// so this is safe to run even if data already exists.
|
||||
if verBefore == 0 && applied > 0 {
|
||||
seedApplied, seedErr := migrations.ApplySeedData(db, logger.Named("migrations"))
|
||||
if seedErr != nil {
|
||||
logger.Warn(fmt.Sprintf("Seed data failed: %s", seedErr.Error()))
|
||||
} else if seedApplied > 0 {
|
||||
logger.Info(fmt.Sprintf("Database: Applied %d seed data file(s)", seedApplied))
|
||||
}
|
||||
}
|
||||
|
||||
// Pre-compute all server IDs this instance will own, so we only
|
||||
// delete our own rows (safe for multi-instance on the same DB).
|
||||
var ownedServerIDs []string
|
||||
|
||||
Reference in New Issue
Block a user