Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postgres - won't detect whether database exists #95

Closed
kuchaguangjie opened this issue Apr 22, 2021 · 8 comments
Closed

postgres - won't detect whether database exists #95

kuchaguangjie opened this issue Apr 22, 2021 · 8 comments
Assignees
Labels

Comments

@kuchaguangjie
Copy link

kuchaguangjie commented Apr 22, 2021

Repeated database creation:

It will still trying create the database, even I have specified dbname=casbin in gorm dsn:

github.com/casbin/gorm-adapter/v3@v3.2.6/adapter.go:237 ERROR: database "casbin" already exists (SQLSTATE 42P04)

Better create only if not exists yet, I guess.

BTW, the 2nd issue about timezone is moved to: #96

@hsluoyz
Copy link
Member

hsluoyz commented Apr 22, 2021

@kuchaguangjie hi, thanks for your bug report! Can you put the 2nd bug to another issue?

@hsluoyz hsluoyz self-assigned this Apr 22, 2021
@hsluoyz hsluoyz added the bug label Apr 22, 2021
@hsluoyz
Copy link
Member

hsluoyz commented Apr 22, 2021

@closetool

@kilosonc
Copy link
Contributor

kilosonc commented Apr 22, 2021

@kuchaguangjie For the first issue, plz see below

NewAdapter is the constructor for Adapter.
Params : databaseName,tableName,dbSpecified
			databaseName,{tableName/dbSpecified}
			{database/dbSpecified}
databaseName and tableName are user defined.
Their default value are "casbin" and "casbin_rule"

dbSpecified is an optional bool parameter. The default value is false.
It's up to whether you have specified an existing DB in dataSourceName.
If dbSpecified == true, you need to make sure the DB in dataSourceName exists.
If dbSpecified == false, the adapter will automatically create a DB named databaseName.

@kilosonc
Copy link
Contributor

kilosonc commented Apr 22, 2021

@kuchaguangjie For the second issue, plz just use lower case, like timezone=Asia/Shanghai

@hsluoyz
Copy link
Member

hsluoyz commented Apr 22, 2021

@kilosonc
Copy link
Contributor

@hsluoyz In official docs, TimeZone was used https://www.postgresql.org/docs/9.2/datatype-datetime.html#DATATYPE-TIMEZONES.
But I tested timezone and it works.
Could you please try it @kuchaguangjie ?

@kuchaguangjie
Copy link
Author

@hsluoyz Moved the 2nd issue to: #96

@kuchaguangjie kuchaguangjie changed the title postgres - won't detect whether database exists, and can't set timezone postgres - won't detect whether database exists Apr 22, 2021
@kuchaguangjie
Copy link
Author

kuchaguangjie commented Apr 22, 2021

@hsluoyz Thanks, for the db creation issue, after add 3rd param as true in NewAdapter(), and specify dbname in gorm dsn, now it won't create db.

Code:

    dsn := "host=localhost user=postgres password=mypswd port=5432 dbname=casbin sslmode=disable"
    a, _ := gormadapter.NewAdapter("postgres", dsn, true)
    ef, _ := casbin.NewEnforcer("/path/to/rcba_model.conf", a)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants