ory / ladon

A SDK for access control policies: authorization for the microservice and IoT age. Inspired by AWS IAM policies. Written for Go.

Home Page:https://www.ory.sh/?utm_source=github&utm_medium=banner&utm_campaign=ladon

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ladon_policy table not getting created

adhicoder opened this issue · 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.