Creating admin using rake admin:create in multisite configuration

AI-generated summary

In a multisite Discourse setup, creating an admin user using rake admin:create only creates the administrator on the first site. To create an admin user for a specific site, you need to switch the database using the RAILS_DB prefix.

Initially, attempts to use RAILS_DB=b_discourse rake admin:create failed, still creating the admin user on the first site Hammad_Abbasi. However, tgxworld suggested using RAILS_DB=b_discourse rails console or RAILS_DB=b_discourse rails runner <command> to switch the database, which worked.

To create an admin user or change the password of an existing user using the Rails console, you can refer to the admin.rake file tgxworld.

Ultimately, Hammad_Abbasi discovered that their app.yml file for the second site had a database name that matched the site’s identifier (secondsitet), not the database name. tgxworld suggested using RAILS_DB=secondsitet instead, which successfully connected to the second database and allowed the creation of an admin user.

Hi,

I am running discourse multi-site setup, I am wondering how can i create administrator using
rake admin:create

It creates the administrator on first site.

You have to switch database using the RAILS_DB=<name_of_db> prefix before the command

RAILS_DB=site1 rake admin:create

It’s still creating admin account for first web site

I am also trying to connect to 2nd database manually using

su -c ‘psql discourse’ postgres

but it throws error “no password entry for user postgres”

Hi,

I have setup a multi-site up and running however I am unable to create admin or configure notification email for 2nd site
so i have few questions

How can i configure SiteSettings in app.yml for a) 2nd Site b) ALL SITES

  • exec: rails r “SiteSetting.notification_email=‘’”

I have tried manually connecting to both databases using
sudo -u postgres psql b_discourse
but when i run select * from users ( it returns nothing )

I tried running “rake admin:create RAILS_DB=b_discourse”- but this is creating the user on first site.

I ran “SiteSetting.notification_email” command in rails console it shows email from 1st Site - is there any way i can switch database in rails console ?

RAILS_DB=b_discourse rails console or RAILS_DB=b_discourse rails runner <command>

Try RAILS_DB=b_discourse rake admin:create?

I did but didn’t work (creating on first site)

I am however able to use 2nd db using "RAILS_DB=b_discourse rails console "
Can i create an admin user or change password of existing user using this console ?

Please advice. Many Thanks for your Help

Hmm I’m not sure why it isn’t working for you. I just tested locally and it works fine.

Yup you can :slight_smile:

Below is my app.yml for 2nd site ( First site is using default - discourse_hostname)

before_bundle_exec:
- file:
path: $home/config/multisite.yml
contents: |
secondsite:
adapter: postgresql
database: b_discourse
pool: 25
timeout: 5000
db_id: 2
host_names:
- community.mydomain.com

I just realized “RAILS_DB=b_discourse rails console” is also connecting to first database

Try RAILS_DB=secondsite instead.

Bingo - It worked :smiley:

Thanks alot