0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 13:08:40 +08:00
discourse/db/post_migrate/20260728162521_backfill_send_shortcut.rb
Keegan George 436041645f
FEATURE: Make the message send shortcut a core user option (#42105)
**Previously**, the enter/meta+enter send shortcut was a chat-only
preference (`chat_send_shortcut`), so chat-style composers in other
plugins — like AI bot conversations — always sent on Enter with no way
to insert a newline.

**In this update**, promoted it to a core `send_shortcut` user option on
the Interface preferences page, honored by the chat composer, the core
docked composer, and AI bot conversations.

The `chat_send_shortcut` column is backfilled into `send_shortcut`
post-deploy and kept (ignored) for now, mirroring the
`push_notification_level` promotion; the column drop, the serializer
compatibility alias removal, and the `plugin_manifest.yml` cleanup land
in a follow-up PR.

| Before | After |
| --- | --- |
|
![before](https://github.com/discourse/discourse/releases/download/_gh-attach-assets/before-jmgi09.png)
|
![after](https://github.com/discourse/discourse/releases/download/_gh-attach-assets/after-crkznx.png)
|
2026-07-28 13:58:12 -07:00

35 lines
977 B
Ruby
Vendored

# frozen_string_literal: true
class BackfillSendShortcut < ActiveRecord::Migration[8.0]
disable_ddl_transaction!
BATCH_SIZE = 30_000
def up
# `chat_send_shortcut` is a chat-plugin column; skip when it isn't present
# (e.g. the chat plugin is absent, or the migrations-tooling core-only
# schema) so this core migration never references a missing column.
return unless column_exists?(:user_options, :chat_send_shortcut)
loop do
count = DB.exec(<<~SQL, batch_size: BATCH_SIZE)
WITH cte AS (
SELECT user_id
FROM user_options
WHERE chat_send_shortcut <> 0 AND send_shortcut <> chat_send_shortcut
LIMIT :batch_size
)
UPDATE user_options
SET send_shortcut = user_options.chat_send_shortcut
FROM cte
WHERE user_options.user_id = cte.user_id
SQL
break if count == 0
end
end
def down
raise ActiveRecord::IrreversibleMigration
end
end