node-casbin / sequelize-adapter

Sequelize adapter for Casbin
https://github.com/casbin/node-casbin
Apache License 2.0
64 stars 34 forks source link

Multiple adapter instance based on postgre schema? #72

Closed shubhanshusingh closed 1 year ago

shubhanshusingh commented 1 year ago

It seems like if I try to create an adapter instance, the last one overrides all previously created. For my application, I have multiple tenants and per tenant Postgres schema is different.

example:

if I init above 3 adapters then it seems like casbinAdapter1 and casbinAdapter2 instance are equivalent to casbinAdapter3. So if I use any adapter in enforcer it always points to the last db adapter instance i.e. tenant3 schema instance.

casbin-bot commented 1 year ago

@nodece @Zxilly @Shivansh-yadav13

shubhanshusingh commented 1 year ago

?? any update on this

hsluoyz commented 1 year ago

@imp2002 @terry-xuan-gao plz take a look

terry-xuan-gao commented 1 year ago

Hi @shubhanshusingh, sorry for taking so long to respond to you. Could you show me the full content of pgOptions1, pgOptions2 and pgOptions3? This will help me figure out this issue : )

shubhanshusingh commented 1 year ago

pgOptions1

{
          database: data.database,
          schema: "tenant1"
          host: data.host,
          port: data.port,
          username: data.username,
          dialect: 'postgres',
          type: 'postgres',
          password: data.password,
          dialectOptions: {
            ssl: {
              rejectUnauthorized: false,
              ca: data.DB_CA,
              key: data.DB_TLS_KEY,
              cert: data.DB_TLS_CERT,
            }
          }
        }

pgOptions2

{
          database: data.database,
          schema: "tenant2"
          host: data.host,
          port: data.port,
          username: data.username,
          dialect: 'postgres',
          type: 'postgres',
          password: data.password,
          dialectOptions: {
            ssl: {
              rejectUnauthorized: false,
              ca: data.DB_CA,
              key: data.DB_TLS_KEY,
              cert: data.DB_TLS_CERT,
            }
          }
        }

pgOptions3

{
          database: data.database,
          schema: "tenant3"
          host: data.host,
          port: data.port,
          username: data.username,
          dialect: 'postgres',
          type: 'postgres',
          password: data.password,
          dialectOptions: {
            ssl: {
              rejectUnauthorized: false,
              ca: data.DB_CA,
              key: data.DB_TLS_KEY,
              cert: data.DB_TLS_CERT,
            }
          }
        }
shubhanshusingh commented 1 year ago

the distinction between pgOptions is the name of the schema.

shubhanshusingh commented 1 year ago

@terry-xuan-gao can we check now?