The discussion revolves around safely inserting users directly into separate Discourse databases. emonunix is looking to automate user creation during setup for multiple isolated Discourse forums, each with its own Postgres database. pfaffman advises that while it’s possible to insert user records directly into the database, it’s safer to have Rails handle it, and notes that the user and user_emails tables must be updated with matching user_ids.
emonunix clarifies that the CSV and API-based methods are too slow for their needs, requiring a faster approach to populate multiple instances with users during provisioning. pfaffman suggests looking at bulk import scripts for examples of direct database updates and asks about the number of users being added and whether the same users are used across sites. The goal is to reduce wait time during setup and achieve near-instant user creation.
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?