Skip to main content
Ask A Question
Notifications
You’re not receiving notifications from this thread.
Subscribe

Multitenancy with Apartment Gem

General • Asked by Tejas Patel

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


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 29,763+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.