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

Reply

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.

Reply

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.

Reply

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.

Reply

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.

Reply

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!

Reply

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..

Reply

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

Reply

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

Reply
Join the discussion
Create an account Log in

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

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

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

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2024 GoRails, LLC. All rights reserved.