Skip to content

A platform for community discussion. Free, open, simple.

DEV: Update DropToolDetailsFromAiPersonas following table rename flip (#38596)

David Taylor7f057488306f
diff --git a/plugins/discourse-ai/db/post_migrate/20260205065417_drop_tool_details_from_ai_personas.rb b/plugins/discourse-ai/db/post_migrate/20260205065417_drop_tool_details_from_ai_personas.rb
index b1d8eb73fb0..db79e3ad0e4 100644
--- a/plugins/discourse-ai/db/post_migrate/20260205065417_drop_tool_details_from_ai_personas.rb
+++ b/plugins/discourse-ai/db/post_migrate/20260205065417_drop_tool_details_from_ai_personas.rb
@@ -2,15 +2,15 @@
class DropToolDetailsFromAiPersonas < ActiveRecord::Migration[8.0]
def up
- view_existed = connection.view_exists?(:ai_agents)
- execute "DROP VIEW IF EXISTS ai_agents" if view_existed
+ view_name = table_exists?(:ai_agents) ? :ai_personas : :ai_agents
+ table_name = table_exists?(:ai_agents) ? :ai_agents : :ai_personas
- Migration::ColumnDropper.execute_drop(:ai_personas, %i[tool_details])
+ view_existed = connection.view_exists?(view_name)
+ execute "DROP VIEW IF EXISTS #{view_name}" if view_existed
- if view_existed
- columns = connection.columns(:ai_personas).map(&:name).join(", ")
- execute "CREATE VIEW ai_agents AS SELECT #{columns} FROM ai_personas"
- end
+ Migration::ColumnDropper.execute_drop(table_name, %i[tool_details])
+
+ execute "CREATE VIEW #{view_name} AS SELECT * FROM #{table_name}" if view_existed
end
def down