| 1 | # frozen_string_literal: true |
| 2 | |
| 3 | # siGit Code Cloud Sessions (short: Cloud Session). A Cloud Session is a named, |
| 4 | # resumable conversation with siGit Code Cloud, persisted server-side so it syncs |
| 5 | # across the web client and any other signed-in surface. Each session pins a |
| 6 | # quality tier (`model` = the neutral wire id, e.g. onde-balanced) and owns an |
| 7 | # ordered list of messages. On-device chat is never stored here. |
| 8 | # |
| 9 | # The session id is a UUID because it appears in a shareable, public-facing URL |
| 10 | # (code.sigit.si/cloud/sessions/<uuid>); a sequential integer would leak volume |
| 11 | # and be guessable. Messages keep a plain bigint id (never surfaced) but key off |
| 12 | # the session UUID. |
| 13 | class CreateCloudSessions < ActiveRecord::Migration[8.1] |
| 14 | def change |
| 15 | create_table :cloud_sessions, id: :uuid do |t| |
| 16 | t.references :user, null: false, foreign_key: true |
| 17 | t.string :title, null: false, default: "New session" |
| 18 | t.string :model, null: false, default: "onde-balanced" |
| 19 | t.datetime :last_message_at |
| 20 | |
| 21 | t.timestamps |
| 22 | end |
| 23 | |
| 24 | add_index :cloud_sessions, %i[user_id updated_at] |
| 25 | |
| 26 | create_table :cloud_messages do |t| |
| 27 | t.references :cloud_session, null: false, foreign_key: true, type: :uuid |
| 28 | t.string :role, null: false |
| 29 | t.text :content, null: false, default: "" |
| 30 | |
| 31 | t.timestamps |
| 32 | end |
| 33 | |
| 34 | add_index :cloud_messages, %i[cloud_session_id created_at] |
| 35 | end |
| 36 | end |