All threads / Multitenancy with Apartment Gem

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Multitenancy with Apartment Gem

Tejas Patel asked in General

Hi Chris,

I am using Postgresql and apartment gem and my database has many views and functions. so I am using

config.use_schemas = true
config.use_sql = true

to use pg_dump but when I run migrations it tries to use normal user account through which I am logged in to my computer rather than the one I provided in my database.yml

Is there any way to provide correct credentials so that pg_dump command can run when I run migrations? Any help would be greatly appreciated.

Thanks

Are you executing pg_dump manually from the command line? I've noticed that when it's run without the user option, it defaults to the current operating system username. Wondering if that is what's happening.

no I am not running it manually - All I am doing is creating new tenant it gives me

pg_dump: [archiver (db)] connection to database "db_name" failed: FATAL: role "computer logged in username" does not exist

somehow it still uses operating system username to run pg_dump - Is there anything else I am missing.

Thanks for your time and support.

It sounds like you may not be passing in the right database username. You should put in the username that you use to login to the database. It will be the same username in your config/database.yml file. For example, mine is -U chris in the command.

Yes you are right - but not sure where should I put my correct username - Does it have any config file where I can put my credentials which then will be used by apartment gem when I create new tenant through active record.

Actually I just found this: https://github.com/influitive/apartment/pull/208

Looks like you might need to set the environment variables he mentioned in order to get pg_dump to run correctly. Wish I had found this earlier for you!

Thanks Chris - seems like they have included in their latest build (but no documentation yest) - I am gonna try and let you know how it goes..

What's the function of "use_schemas = true"? Thanks.

@Vitor the Apartment docs should have a good explanation for that. 👍

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 35,699+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.