-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
37 lines (31 loc) · 935 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
package main
import (
"log"
"os"
_ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
"github.com/joho/godotenv"
"github.com/webstradev/rsdb-migrator/importer"
"github.com/webstradev/rsdb-migrator/migrations"
)
func main() {
// If a database connection string is not yet set in environment variables (or by kube secrets) then load the .env file
if os.Getenv("DB_CONNECTION_STRING") == "" {
err := godotenv.Load(".env")
if err != nil {
log.Fatalf("Error loading environment file: %v", err)
}
}
// Import the necessary json files from the mongodumps folder
data, err := importer.ImportFiles("./mongodumps")
if err != nil {
log.Fatalf("Error importing files: %v", err)
}
// Create database connection
db, err := sqlx.Open("mysql", os.Getenv("DB_CONNECTION_STRING"))
if err != nil {
log.Fatalf("Could not open database connection: %v", err)
}
// Run Migrations
migrations.Migrate(db, data)
}