rails-on-services/apartment

Did anybody switch back from multi-schema to one shared schema?

krtschmr opened this issue · 8 comments

We are discussing to drop the multi schema approach (for certain models) and instead move to one shared table/db for maintenance reasons.
Did somebody took a similar step already?

We already use UUID for every record, so i assume all we need to do is prefix certain toplevel models with user_id and client_id, then squeeze data from schema tables into one and problem is solved?

pgouv commented

I would like to do this too but we are not there yet. You should also take care of associations somehow because there is nothing preventing someone supplying an relation_id to an id that you do not want.

I would like to do this too but we are not there yet. You should also take care of associations somehow because there is nothing preventing someone supplying an relation_id to an id that you do not want.

if you always scope down with ActiveRecord, nothing shall happen

before, with extra shema per tenant we could just do

chapter = Chapter.find(params[:chapter_id]

now it needs to be

document = current_user.documents.find(params[:document_id]
chapter = document.chapters.find(params[:chapter_id])

is this what you mean with "taking care of associations"?

pgouv commented

If you have a form for Document with a field chapter_id then you should filter somehow chapter_id input because a malicious user could set this to any value for example an id from another tenant.

If you have a form for Document with a field chapter_id then you should filter somehow chapter_id input because a malicious user could set this to any value.

yeah i know those issues, but with good activerecord scoping this isn't an issue at all. (also, we don't have those forms. 🤞🏿 )

Do you see any other issues with such an approach?

pgouv commented

I haven't tried so I do not know. One issue that I have is that I haven't found an easy way to generate sequential ids. I need this for a single model out of the 200 I have

we switched to UUIDs, so that means we could just merge data tables together and have no ID fuzz.

Closing this as does not seem relevant for ros-apartment itself.