diff --git a/internal/db/migrations/20260219203524_player_names.go b/internal/db/migrations/20260219203524_player_names.go new file mode 100644 index 0000000..35dbf23 --- /dev/null +++ b/internal/db/migrations/20260219203524_player_names.go @@ -0,0 +1,31 @@ +package migrations + +import ( + "context" + + "git.haelnorr.com/h/oslstats/internal/db" + "github.com/uptrace/bun" +) + +func init() { + Migrations.MustRegister( + // UP migration + func(ctx context.Context, conn *bun.DB) error { + // Add your migration code here + _, err := conn.NewAddColumn(). + Model((*db.Player)(nil)). + IfNotExists(). + ColumnExpr("name VARCHAR NOT NULL"). + Exec(ctx) + if err != nil { + return err + } + return nil + }, + // DOWN migration + func(ctx context.Context, conn *bun.DB) error { + // Add your rollback code here + return nil + }, + ) +} diff --git a/internal/db/player.go b/internal/db/player.go index 690cd37..774b20d 100644 --- a/internal/db/player.go +++ b/internal/db/player.go @@ -14,6 +14,7 @@ type Player struct { SlapID *uint32 `bun:"slap_id,unique" json:"slap_id"` DiscordID string `bun:"discord_id,unique,notnull" json:"discord_id"` UserID *int `bun:"user_id,unique" json:"user_id"` + Name string `bun:"name,notnull" json:"name"` User *User `bun:"rel:belongs-to,join:user_id=id" json:"-"` } diff --git a/internal/discord/config.go b/internal/discord/config.go index f8b96de..e263445 100644 --- a/internal/discord/config.go +++ b/internal/discord/config.go @@ -14,6 +14,7 @@ type Config struct { OAuthScopes string // Authorisation scopes for OAuth RedirectPath string // ENV DISCORD_REDIRECT_PATH: Path for the OAuth redirect handler (required) BotToken string // ENV DISCORD_BOT_TOKEN: Token for the discord bot (required) + GuildID string // ENV DISCORD_GUILD_ID: ID for the discord server the bot should connect to (required) } func ConfigFromEnv() (any, error) { @@ -23,6 +24,7 @@ func ConfigFromEnv() (any, error) { OAuthScopes: getOAuthScopes(), RedirectPath: env.String("DISCORD_REDIRECT_PATH", ""), BotToken: env.String("DISCORD_BOT_TOKEN", ""), + GuildID: env.String("DISCORD_GUILD_ID", ""), } // Check required fields @@ -38,6 +40,9 @@ func ConfigFromEnv() (any, error) { if cfg.BotToken == "" { return nil, errors.New("Envar not set: DISCORD_BOT_TOKEN") } + if cfg.GuildID == "" { + return nil, errors.New("Envar not set: DISCORD_GUILD_ID") + } return cfg, nil } diff --git a/internal/permissions/constants.go b/internal/permissions/constants.go index f7114d1..c2912fb 100644 --- a/internal/permissions/constants.go +++ b/internal/permissions/constants.go @@ -24,10 +24,11 @@ const ( LeaguesDelete Permission = "leagues.delete" // Teams permissions - TeamsCreate Permission = "teams.create" - TeamsUpdate Permission = "teams.update" - TeamsDelete Permission = "teams.delete" - TeamsAddToLeague Permission = "teams.add_to_league" + TeamsCreate Permission = "teams.create" + TeamsUpdate Permission = "teams.update" + TeamsDelete Permission = "teams.delete" + TeamsAddToLeague Permission = "teams.add_to_league" + TeamsManagePlayers Permission = "teams.manage_players" // Users permissions UsersUpdate Permission = "users.update" diff --git a/internal/view/seasonsview/season_league_teams.templ b/internal/view/seasonsview/season_league_teams.templ index d05ccdf..2ae3944 100644 --- a/internal/view/seasonsview/season_league_teams.templ +++ b/internal/view/seasonsview/season_league_teams.templ @@ -122,7 +122,7 @@ templ SeasonLeagueTeams(season *db.Season, league *db.League, teams []*db.Team, } else {