discourse-ai/db/migrate/20231202013850_convert_ai_personas_commands_to_json.rb
Sam 6380ebd829
FEATURE: allow personas to provide command options (#331)
Personas now support providing options for commands.

This PR introduces a single option "base_query" for the SearchCommand. When supplied all searches the persona will perform will also include the pre-supplied filter.

This can allow personas to search a subset of the forum (such as documentation)

This system is extensible we can add options to any command trivially.
2023-12-08 08:42:56 +11:00

32 lines
888 B
Ruby

# frozen_string_literal: true
class ConvertAiPersonasCommandsToJson < ActiveRecord::Migration[7.0]
def up
# this all may be a bit surprising, but interestingly this makes all our backend code
# cross compatible
# upgrading ["a", "b", "c"] to json simply works cause in both cases
# rails will cast to a string array and all code simply expectes a string array
#
# this change was made so we can also start storing parameters with the commands
execute <<~SQL
ALTER TABLE ai_personas
ALTER COLUMN commands DROP DEFAULT
SQL
execute <<~SQL
ALTER TABLE ai_personas
ALTER COLUMN commands
TYPE json USING array_to_json(commands)
SQL
execute <<~SQL
ALTER TABLE ai_personas
ALTER COLUMN commands
SET DEFAULT '[]'::json
SQL
end
def down
raise ActiveRecord::IrreversibleMigration
end
end