init
This commit is contained in:
commit
b15b95781c
108 changed files with 14802 additions and 0 deletions
34
cmd/migrate/main.go
Normal file
34
cmd/migrate/main.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"update_server/internal/config"
|
||||
"update_server/internal/db"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg, err := config.Load()
|
||||
if err != nil {
|
||||
exitWithError(err)
|
||||
}
|
||||
|
||||
database, err := db.Open(context.Background(), cfg.SQLitePath)
|
||||
if err != nil {
|
||||
exitWithError(err)
|
||||
}
|
||||
defer database.Close()
|
||||
|
||||
if err := db.Migrate(context.Background(), database, cfg.MigrationsDir); err != nil {
|
||||
exitWithError(err)
|
||||
}
|
||||
|
||||
fmt.Fprintf(os.Stdout, "migrations applied successfully to %s\n", cfg.SQLitePath)
|
||||
}
|
||||
|
||||
func exitWithError(err error) {
|
||||
fmt.Fprintf(os.Stderr, "update_server migrate: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue