Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions server/configuration/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (
"WARN": true,
"ERROR": true,
}
validLanguages = map[string]bool{
ValidLanguages = map[string]bool{
"en": true,
"de": true,
}
Expand Down Expand Up @@ -46,7 +46,7 @@ func validateConfiguration() {
configErrors = append(configErrors, fmt.Errorf("admin.password is empty, please set a password"))
}

if !validLanguages[systemConfiguration.System.Frontend.DefaultLanguage] {
if !ValidLanguages[systemConfiguration.System.Frontend.DefaultLanguage] {
configErrors = append(configErrors, fmt.Errorf("system.frontend.default_language has to be either 'en', or 'de'"))
}

Expand Down
48 changes: 8 additions & 40 deletions server/db/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/FachschaftMathPhysInfo/kummerkasten/configuration"
"github.com/FachschaftMathPhysInfo/kummerkasten/migrations"
"github.com/FachschaftMathPhysInfo/kummerkasten/models"
"github.com/uptrace/bun"
"github.com/uptrace/bun/dialect/pgdialect"
Expand All @@ -17,21 +18,9 @@ import (
)

var (
db *bun.DB
sqldb *sql.DB
err error
tables = []interface{}{
(*models.User)(nil),
(*models.Label)(nil),
(*models.Setting)(nil),
(*models.Ticket)(nil),
(*models.QuestionAnswerPair)(nil),
(*models.Session)(nil),
}

relations = []interface{}{
(*models.LabelsToTickets)(nil),
}
db *bun.DB
sqldb *sql.DB
err error
)

const MaxDbPings = 10
Expand Down Expand Up @@ -67,34 +56,13 @@ func Init(ctx context.Context) (*sql.DB, *bun.DB) {
}

db = bun.NewDB(sqldb, pgdialect.New())
db.AddQueryHook(bundebug.NewQueryHook())
db.WithQueryHook(bundebug.NewQueryHook())
db.RegisterModel((*models.LabelsToTickets)(nil))

if err := createTables(ctx, tables); err != nil {
slog.Error("Failed to create basic tabels", "error", err)
panic("Failed to create basic tables")
}

slog.Info("Basic Database Tables successfully initialized")

if err := createTables(ctx, relations); err != nil {
slog.Error("Failed to create basic relations", "error", err)
panic("Failed to create basic relations")
if err := migrations.RunMigrations(db, ctx); err != nil {
slog.Error("Error running migrations. To save the data from corruption the service will abort.", "error", err)
panic(err)
}

slog.Info("Basic Database Relations successfully initialized")

return sqldb, db
}

func createTables(ctx context.Context, tables []interface{}) error {
for _, table := range tables {
if _, err := db.NewCreateTable().
Model(table).
IfNotExists().
Exec(ctx); err != nil {
return err
}
}
return nil
}
6 changes: 3 additions & 3 deletions server/db/seed.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func seedTestData(ctx context.Context, db *bun.DB) error {

func removeTestUsers(ctx context.Context, db *bun.DB) error {
slog.Info("Removing test users...")
if _, err := db.NewDelete().Model((*models.User)(nil)).Where("mail IN (?)", bun.In(testEmails)).Exec(ctx); err != nil {
if _, err := db.NewDelete().Model((*models.User)(nil)).Where("mail IN (?)", bun.List(testEmails)).Exec(ctx); err != nil {
return err
}
slog.Info("Test users removed!")
Expand Down Expand Up @@ -202,7 +202,7 @@ func createSettings(ctx context.Context, db *bun.DB) error {

if err := db.NewSelect().
Model(&existing).
Where("key IN (?)", bun.In(keys)).
Where("key IN (?)", bun.List(keys)).
Scan(ctx); err != nil {
return fmt.Errorf("failed to fetch settings: %w", err)
}
Expand Down Expand Up @@ -660,7 +660,7 @@ func insertData[T any](ctx context.Context, db *bun.DB, model T, data []T, descr
if _, err := db.NewInsert().Model(&data).Exec(ctx); err != nil {
return fmt.Errorf("%s: %s", description, err)
}
slog.Info(fmt.Sprintf("%s seeded successfully\n", description))
slog.Info(fmt.Sprintf("%s seeded successfully", description))
}
return nil
}
52 changes: 25 additions & 27 deletions server/go.mod
Original file line number Diff line number Diff line change
@@ -1,58 +1,56 @@
module github.com/FachschaftMathPhysInfo/kummerkasten

go 1.24.3
go 1.25.0

require (
github.com/99designs/gqlgen v0.17.76
github.com/go-chi/chi/v5 v5.2.2
github.com/99designs/gqlgen v0.17.89
github.com/go-chi/chi/v5 v5.2.5
github.com/google/uuid v1.6.0
github.com/knadh/koanf/parsers/json v1.0.0
github.com/knadh/koanf/providers/env/v2 v2.0.0
github.com/knadh/koanf/providers/file v1.2.1
github.com/knadh/koanf/v2 v2.3.0
github.com/knadh/koanf/v2 v2.3.4
github.com/robfig/cron v1.2.0
github.com/rs/cors v1.11.1
github.com/vektah/gqlparser/v2 v2.5.30
github.com/vektah/gqlparser/v2 v2.5.32
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/fatih/color v1.19.0 // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
github.com/go-viper/mapstructure/v2 v2.5.0 // indirect
github.com/goccy/go-yaml v1.19.2 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/knadh/koanf/maps v0.1.2 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-isatty v0.0.21 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/puzpuzpuz/xsync/v3 v3.5.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sosodev/duration v1.3.1 // indirect
github.com/urfave/cli/v2 v2.27.7 // indirect
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 // indirect
go.opentelemetry.io/otel v1.37.0 // indirect
go.opentelemetry.io/otel/trace v1.37.0 // indirect
golang.org/x/mod v0.29.0 // indirect
golang.org/x/sync v0.18.0 // indirect
golang.org/x/text v0.31.0 // indirect
golang.org/x/tools v0.38.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
github.com/sosodev/duration v1.4.0 // indirect
github.com/urfave/cli/v3 v3.7.0 // indirect
go.opentelemetry.io/otel v1.43.0 // indirect
go.opentelemetry.io/otel/trace v1.43.0 // indirect
golang.org/x/mod v0.35.0 // indirect
golang.org/x/sync v0.20.0 // indirect
golang.org/x/text v0.36.0 // indirect
golang.org/x/tools v0.44.0 // indirect
)

require (
github.com/agnivade/levenshtein v1.2.1 // indirect
github.com/gorilla/websocket v1.5.3
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/lib/pq v1.10.9
github.com/lib/pq v1.12.3
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
github.com/uptrace/bun v1.2.15
github.com/uptrace/bun/dialect/pgdialect v1.2.15
github.com/uptrace/bun/driver/pgdriver v1.2.15
github.com/uptrace/bun/extra/bundebug v1.2.14
github.com/uptrace/bun v1.2.18
github.com/uptrace/bun/dialect/pgdialect v1.2.18
github.com/uptrace/bun/driver/pgdriver v1.2.18
github.com/uptrace/bun/extra/bundebug v1.2.18
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
golang.org/x/crypto v0.45.0
golang.org/x/sys v0.39.0 // indirect
golang.org/x/crypto v0.50.0
golang.org/x/sys v0.43.0 // indirect
mellium.im/sasl v0.3.2 // indirect
)
Loading
Loading