discourse-ai/db/migrate/20240309034751_add_shared_ai_conversations.rb
Sam a03bc6ddec
FEATURE: Share conversations with AI via a URL (#521)
This allows users to share a static page of an AI conversation with
the rest of the world.

By default this feature is disabled, it is enabled by turning on
ai_bot_allow_public_sharing via site settings

Precautions are taken when sharing

1. We make a carbonite copy
2. We minimize work generating page
3. We limit to 100 interactions
4. Many security checks - including disallowing if there is a mix
of users in the PM.

* Bonus commit, large PRs like this PR did not work with github tool
large objects would destroy context


Co-authored-by: Martin Brennan <martin@discourse.org>
2024-03-12 16:51:41 +11:00

28 lines
908 B
Ruby

# frozen_string_literal: true
class AddSharedAiConversations < ActiveRecord::Migration[7.0]
def up
create_table :shared_ai_conversations do |t|
t.integer :user_id, null: false
t.integer :target_id, null: false
t.string :target_type, null: false, max_length: 100
t.string :title, null: false, max_length: 1024
t.string :llm_name, null: false, max_length: 1024
t.jsonb :context, null: false
t.string :share_key, null: false, index: { unique: true }
t.string :excerpt, null: false, max_length: 10_000
t.timestamps
end
add_index :shared_ai_conversations, %i[target_id target_type], unique: true
add_index :shared_ai_conversations,
%i[user_id target_id target_type],
unique: true,
name: "idx_shared_ai_conversations_user_target"
end
def down
drop_table :shared_ai_conversations
end
end