Distilling this from Latest update won't build due to AI plugin since that topic is about three different issues at the moment.
Problem:
When trying to update Discourse with the AI plugin installed, the update yields an error with
PG::UndefinedColumn: ERROR: column llm_models.url does not exist
LINE 1: SELECT "llm_models".* FROM "llm_models" WHERE "llm_models"
and renders Discourse unusable until the AI plugin is removed.
When does this happen:
When updating an instance with the AI plugin
From a version that does not have the migration 20240514171609
yet
To commit 8d5f901 or newer
(My main question was why this only happens when updating an already-installed plugin and not when the plugin is newly installed. The answer is that core catches PG::UndefinedTable
exceptions but not PG:UndefinedColumn
. If the plugin is already installed then the exception is the latter, if the plugin is brand new then it is the former).
Reason:
plugin.rb
calls LlmModel.enable_or_disable_srv_llm!
which depends on the column llm_models.url
being present. But if migration 20240514171609
(which adds that column) has not been applied yet, it crashes.
The problem is that db:migrate
also runs this code, which crashes the rake task before the migration can be applied.
Suggested workarounds / fixes:
- change the code to
LlmModel.enable_or_disable_srv_llm! if Discourse.running_in_rack?
(sodb:migrate
does not call it)
or - change the code to
LlmModel.enable_or_disable_srv_llm! rescue nil
(so it does not crash)
or - change the bootstrapping code in core to catch
PG::UndefinedColumn
in addition toPG::UndefinedTable
(so this and future similar issues are caught)