ory/ladon

ladon_policy table not getting created

Closed this issue · 3 comments

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".

The code is hard to read because its not formatted, could you please fix that?

The most likely reason is that you forgot to run CreateSchemas.

Yes, using CreateSchemas solved the problem (partially). While creating the db object, it is also necessary to set parseTime to true. The documentation can be more comprehensive (as pointed out in another issue, sqlx must be used instead of sql). Please consider editing it.

While you're at it, could you improve those sections in a PR? That would be really helpful.