43 lines
857 B
Go
43 lines
857 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
|
|
"git.mziesel.nl/mans/zadmin/database"
|
|
"git.mziesel.nl/mans/zadmin/internal/models"
|
|
"github.com/jmoiron/sqlx"
|
|
_ "github.com/lib/pq"
|
|
"github.com/oklog/ulid/v2"
|
|
)
|
|
|
|
func main() {
|
|
db, err := sqlx.Open("postgres", "user=zadmin_user password=s3cret! dbname=zadmin_dev sslmode=disable host=localhost")
|
|
if err != nil {
|
|
log.Fatalf("goose: failed to open DB: %v\n", err)
|
|
}
|
|
|
|
defer func() {
|
|
if err := db.Close(); err != nil {
|
|
log.Fatalf("failed to close DB: %v\n", err)
|
|
}
|
|
}()
|
|
|
|
createTestMachines(db)
|
|
}
|
|
|
|
func createTestMachines(db *sqlx.DB) {
|
|
machine := models.Machine{
|
|
Id: ulid.Make(),
|
|
MachineName: "test-machine",
|
|
OsType: "linux",
|
|
OsArch: "amd64",
|
|
}
|
|
fmt.Println(models.PrettyFormatData(machine))
|
|
|
|
err := database.CreateMachine(db, &machine)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|