带有golang的ory / ladon管理器-未创建表

github.com/ory/ladon is a library to manage role based access, written in golang. It contains a manager that is supposed to persist policies in the database and work with the database. The manager works fine for the in-memory case. When I use the manager to interface with sql, the required tables are not getting created.

db, err := sqlx.Open("mysql", "tx81:@tcp(127.0.0.1:3306)/policies")
......
err=db.Ping()
if err == nil {
    fmt.Printf("Database is up")
}

warden := ladon.Ladon{
    Manager: manager.NewSQLManager(db, nil),
}

var pol = &ladon.DefaultPolicy{
    ......
}
err = warden.Manager.Create(pol)
fmt.Printf("%s", err)

The error is printed as:

Table 'policies.ladon_policy' doesn't exist.

Why aren't the tables getting created?

Resources: https://github.com/ory/ladon#persistence

You need to call manager.CreateSchemas, which is never done by the manager itself.

You provide it with the schema name (postgresql only I believe) and table name to keep track of migration info.

eg:

if num, err := m.CreateSchemas("", "my_migration_table"); err != nil {
  panic(err)
} else {
  log.Infof("ran %d migrations", num)
}

It could probably use more documentation, you may want to file an issue with the author.