aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2026-03-08 13:38:10 +0100
committerAnhgelus Morhtuuzh <william@herges.fr>2026-03-08 13:38:10 +0100
commitddd6306752186c149f8ad3bf2f59b5428cf01296 (patch)
tree0e40562ef636a9a76cc298e8695cc04abbdcfda5 /main.go
parent88e1b886e5471552c055374f71d848d3a3dcb4b6 (diff)
feat(db): run migrations
Diffstat (limited to 'main.go')
-rw-r--r--main.go19
1 files changed, 11 insertions, 8 deletions
diff --git a/main.go b/main.go
index 1a66b5a..59ba4ca 100644
--- a/main.go
+++ b/main.go
@@ -2,7 +2,7 @@ package main
import (
"context"
- _ "embed"
+ "embed"
"flag"
"log/slog"
"math/rand/v2"
@@ -51,6 +51,9 @@ var finishDeploy context.CancelFunc
//go:embed assets/inter-variable.ttf
var interTTF []byte
+//go:embed migrations
+var migrations embed.FS
+
func init() {
flag.StringVar(&token, "token", os.Getenv("TOKEN"), "token of the bot")
flag.StringVar(&cfgPath, "config", cfgPath, "config's path")
@@ -87,7 +90,13 @@ func main() {
panic(err)
}
- err = db.AutoMigrate(&user.Copaing{}, &config.Guild{}, &config.XpRole{}, &user.CopaingXP{}, &config.RoleReactMessage{}, &config.RoleReact{})
+ logLevel := slog.LevelInfo
+ if verbose || cfg.Debug {
+ logLevel = slog.LevelDebug
+ }
+ dg := gokord.NewWithLogLevel("Bot "+token, logLevel)
+
+ err = common.Migrate(context.Background(), dg.Logger(), db, migrations, "migrations")
if err != nil {
panic(err)
}
@@ -97,12 +106,6 @@ func main() {
ctx = common.SetDebug(ctx, cfg.Debug)
ctx = common.SetAuthor(ctx, cfg.Author)
- logLevel := slog.LevelInfo
- if verbose || cfg.Debug {
- logLevel = slog.LevelDebug
- }
- dg := gokord.NewWithLogLevel("Bot "+token, logLevel)
-
dg.Identify.Intents = discord.IntentsAllWithoutPrivileged |
discord.IntentsMessageContent |
discord.IntentGuildMembers