We’re running multiple Discourse forums as isolated instances on the same virtual machine. Each forum has its own separate Postgres database, but they’re all managed by a shared script that runs on the host machine.
We’re looking to automate the creation of initial users during setup. Rather than using the API or CSV importer, we’re wondering:
Is it possible (and safe) to insert user records directly into each instance’s database?
Since our script already interacts with the databases, this could streamline the provisioning process significantly.
Has anyone attempted direct DB user creation before? Or is this a bad idea due to risks with data integrity, sessions, or other Discourse-specific mechanisms?
Appreciate any advice or experience you can share!
It’s a bit safer having Rails do it than modifying the database yourself, but you can do it if you want. Note that you have to touch at least the user and user_emails tables, and see that the user_ids match.
Thanks, @pfaffman — really appreciate the guidance!
Just to clarify: one of the main reasons we’re exploring this route is that both the CSV and API-based methods are too slow for what we’re trying to do. We’re spinning up lots of isolated instances and need to populate each one with a batch of users quickly during provisioning.
Would the fixtures/plugin approach you mentioned allow for significantly faster user creation compared to the API or CSV methods? Specifically, we’re hoping to reduce wait time during setup — ideally something that executes instantly or near-instantly along with the initial DB setup.
You can look at the bulk import scripts for examples of updating the database directly. The import script does have some overhead, so maybe the example in the fixtures chilly be some faster?
How many users are you adding? Do you have the same users for each site?