-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
main.go
44 lines (36 loc) · 903 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"context"
"os"
_ "github.com/lib/pq"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
modelgen "atomys.codes/stud42/internal/models/generated"
)
var client *modelgen.Client
func init() {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
if os.Getenv("DEBUG") == "true" {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
} else {
zerolog.SetGlobalLevel(zerolog.InfoLevel)
}
var err error
client, err = modelgen.Open(
"postgres",
os.Getenv("DATABASE_URL"),
modelgen.Debug(),
)
if err != nil {
log.Fatal().Err(err).Msg("failed to connect to database")
}
if err := client.Schema.Create(context.Background()); err != nil {
log.Fatal().Err(err).Msg("running schema migration")
}
}
func main() {
if err := seedUsers(); err != nil {
log.Fatal().Err(err).Msg("failed to seed users")
}
}