-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
54 lines (45 loc) · 1.16 KB
/
main.go
File metadata and controls
54 lines (45 loc) · 1.16 KB
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
45
46
47
48
49
50
51
52
53
54
package main
import (
"flag"
"fmt"
"os"
"github.com/fatih/color"
"github.com/pocketbase/pocketbase"
)
func main() {
if err := run(); err != nil {
color.Red(err.Error())
os.Exit(1)
}
}
func run() error {
// Load config from user specified config.json file
// ---------------------------------------------------------------
var configPath string
flag.StringVar(&configPath, "config", "./config.json", "Path to the migration config json file")
flag.Parse()
config, err := NewConfigFromJson(configPath)
if err != nil {
return err
}
if err := config.Validate(); err != nil {
return fmt.Errorf("[config error] %w", err)
}
// Init Presentator v3 app
// ---------------------------------------------------------------
app := pocketbase.NewWithConfig(pocketbase.Config{
DefaultDataDir: config.V3DataDir,
})
defer app.ResetBootstrapState()
if err := app.Bootstrap(); err != nil {
return err
}
// Migrate
// ---------------------------------------------------------------
migrator, err := NewMigrator(app, config)
if err != nil {
return fmt.Errorf("failed to initialize migrator: %w", err)
}
defer migrator.Close()
return migrator.MigrateAll()
}