Skip to content

Multiple adapter instance based on postgres schema(already opened before) #78

@tsoultanopoulos

Description

@tsoultanopoulos

It appears that this issue has already been raised and supposedly, it was solved with this PR, but even after installing the latest version of the adapter(v2.6.1), the problem still persists. In the previous issue (as this) provided three sets of options for connecting to different schemas in the same database. However, when running the code, the last adapter seems to override the other two, preventing you from opening different database connections. The only difference among the options is the schema.

const pgOptions1 = {
  username: 'some_user',
  host: 'some_host',
  port: XXXX,
  password: 'some_password',
  database: 'some_db',
  schema: "tenant1",
  logging: false,
  dialect: 'postgres'
};

const pgOptions2 = {
  username: 'some_user',
  host: 'some_host',
  port: XXXX,
  password: 'some_password',
  database: 'some_db',
  schema: "tenant2",
  logging: false,
  dialect: 'postgres'
};

const pgOptions3 = {
  username: 'some_user',
  host: 'some_host',
  port: XXXX,
  password: 'some_password',
  database: 'some_db',
  schema: "tenant3",
  logging: false,
  dialect: 'postgres'
};

async function run() {
  const casbinAdapter1 = await SequelizeAdapter.newAdapter(pgOptions1);
  const casbinAdapter2 = await SequelizeAdapter.newAdapter(pgOptions2);
  const casbinAdapter3 = await SequelizeAdapter.newAdapter(pgOptions3);

  const enforcer1 = await casbin.newEnforcer('abac_model.conf', casbinAdapter1);
  const enforcer2 = await casbin.newEnforcer('abac_model.conf', casbinAdapter2);
  const enforcer3 = await casbin.newEnforcer('abac_model.conf', casbinAdapter3);

  const p = ['sub', 'obj', 'act'];
 // this add policy at tenant3 
  await enforcer2.addPolicy(...p);
 
}

run().catch(console.error);

Could you please verify if the problem is resolved?

Thank you in advance

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions