NoBrainerORM / nobrainer

Ruby ORM for RethinkDB
http://nobrainer.io/
Other
387 stars 49 forks source link

Index for multi tenancy #263

Closed kp666 closed 1 year ago

kp666 commented 4 years ago

is it possible to sync indices in a multi tenancy setup?

I could add it to documentation with the relevant guideline.

zedtux commented 3 years ago

Can you please elaborate on this? What do you mean by syncing indexes?

kp666 commented 3 years ago

When you do Nobrainer.sync_schema, it loads table names from models. But when you have multi tenancy setup, all table names wont be loaded. Correct me if I am wrong in this assumption.

zedtux commented 3 years ago

Does it mean the doc is not covering this case?

kp666 commented 3 years ago

It does when a seperate db is used, but not in the case of seperate models for each tenant. For example:

class Project
table_config :name => ->{ "project_#{Thread.current[:client]}" }
end

I would not be able to make indices for each client as when the models are loaded, it will only create indices for one table. So what I am doing right now is something like this:

class Project
  def configure_table(name)
    table_config(name: name)
    return unless NoBrainer.run(rql_table.index_status).blank?
    NoBrainer.sync_indexes # Ideally I only want to index this table
  end
end
zedtux commented 1 year ago

I think this behaviour is not supported by this gem, and it wouldn't since what you said is true:

when you have multi tenancy setup, all table names wont be loaded.

You need your own task to load each of your clients in order to get the Thread.current[:client] being filled before to call the sync_indexes and it's what you're doing already.

I'm closing this but in the case there's something we can do in this gem to help, feel free to re-open it or open a new one.