Just a report back for future onlookers that the rake task that was run in OP was using
bundle exec rake doc_categories:build_sidebar
and met with the error
ActiveRecord::NoDatabaseError: We could not find your database: discourse. Available database configurations can be found in config/database.yml. (ActiveRecord::NoDatabaseError)
Depending on self-hosted setups, it is likely that the task needs to be run with the discourse
user to get to the database.
sudo -E -u discourse bundle exec rake doc_categories:build_sidebar
@MachineScholar has confirmed that the sections and links have thus been successfully created.