casbin / xorm-adapter

Xorm adapter for Casbin
https://github.com/casbin/casbin
Apache License 2.0
384 stars 58 forks source link

Error while creating new adpator #67

Open VaishnavcveeZ opened 3 weeks ago

VaishnavcveeZ commented 3 weeks ago

Gettting error while running application code for creating adaptor. The error will happen at the 2nd time.

Error - pq: relation \"IDX_casbin_rule_ptype\" already exists"

Steps- 1 . Create table for casbin CREATE TABLE IF NOT EXISTS "casbin_rule" ( "id" VARCHAR(100) NOT NULL PRIMARY KEY DEFAULT gen_random_uuid(), "ptype" VARCHAR(100) NOT NULL , "v0" VARCHAR(100) NOT NULL, "v1" VARCHAR(100) NOT NULL, "v2" VARCHAR(100) NOT NULL, "v3" VARCHAR(100) NOT NULL, "v4" VARCHAR(100), "v5" VARCHAR(100) );

  1. Run application with adaptor code

dsn := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s search_path=%s timezone=%s sslmode=disable", Host, Port, User, Password, DbName, Schema, Timezone)

xormAdaptor, err := xormadapter.NewAdapter("postgres", dsn, true) if err != nil { slog.Error("xormadapter.NewAdapter", "err", err) return err }

  1. Run the application first time will create an index for colum "ptype" - IDX_casbin_rule_ptype. While running 2nd time will get an error for the existing index.
hsluoyz commented 3 weeks ago

@VaishnavcveeZ can you make a PR?