package main
import “github.com/ory/ladon”
import manager “github.com/ory/ladon/manager/sql”
import “github.com/jmoiron/sqlx”
import (
_ “github.com/go-sql-driver/mysql”
“log”
“fmt”
)
func main() {
// The database manager expects a sqlx.DB object
//
// For MySQL, be sure to include parseTime=true in the connection string
// You can find all of the supported MySQL connection string options for the
// driver at: https://github.com/go-sql-driver/mysql
//
db, err := sqlx.Open(“mysql”, “:@tcp(0.0.0.0:32768)/?parseTime=true”)
// Or, if using postgres:
// import _ “github.com/lib/pq”
//
// db, err = sqlx.Open(“postgres”, “postgres://foo:bar@localhost/ladon”)
if err != nil {
log.Fatalf(“Could not connect to database: %s”, err)
}
warden := &ladon.Ladon{
Manager: manager.NewSQLManager(db, nil),
}
fmt.Println(warden)
// You must call SQLManager.CreateSchemas(schema, table) before use
// to apply the necessary SQL migrations
//
// You can provide your own schema and table name or pass
// empty strings to use the default
n, err := warden.Manager.CreateSchemas("", "my-migration-table")
if err != nil {
log.Fatalf("Failed to create schemas: %s", err)
}
log.Printf("applied %d migrations", n)
// ...
}