Skip to content

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

FIX: Improve voice -> live rename implementation (#44847)

David Taylor6aceaa778cdd
diff --git a/db/structure.sql b/db/structure.sql
index 48b02ee6af6..ea995b03c83 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -26090,6 +26090,7 @@ ALTER TABLE ONLY public.ad_plugin_house_ads_groups
SET search_path TO "$user", public;
INSERT INTO "schema_migrations" (version) VALUES
+('20261020161054'),
('20261019105124'),
('20261019104439'),
('20261018172000'),
diff --git a/plugins/live/db/post_migrate/20260703134812_remove_voice_noise_suppression_setting.rb b/plugins/live/db/migrate/20260703134812_remove_voice_noise_suppression_setting.rb
similarity index 100%
rename from plugins/live/db/post_migrate/20260703134812_remove_voice_noise_suppression_setting.rb
rename to plugins/live/db/migrate/20260703134812_remove_voice_noise_suppression_setting.rb
diff --git a/plugins/live/db/post_migrate/20260803163214_remove_voice_sessions_room_foreign_key.rb b/plugins/live/db/migrate/20260803163214_remove_voice_sessions_room_foreign_key.rb
similarity index 85%
rename from plugins/live/db/post_migrate/20260803163214_remove_voice_sessions_room_foreign_key.rb
rename to plugins/live/db/migrate/20260803163214_remove_voice_sessions_room_foreign_key.rb
index ce25775540f..3cf87a73410 100644
--- a/plugins/live/db/post_migrate/20260803163214_remove_voice_sessions_room_foreign_key.rb
+++ b/plugins/live/db/migrate/20260803163214_remove_voice_sessions_room_foreign_key.rb
@@ -4,7 +4,11 @@
# which the FK made impossible (room destroy raised ForeignKeyViolation).
class RemoveVoiceSessionsRoomForeignKey < ActiveRecord::Migration[8.0]
def up
+ Migration::SafeMigrate.disable!
+
remove_foreign_key :voice_sessions, column: :room_id, if_exists: true
+ ensure
+ Migration::SafeMigrate.enable!
end
def down
diff --git a/plugins/live/db/post_migrate/20260803163818_remove_voice_user_foreign_keys.rb b/plugins/live/db/migrate/20260803163818_remove_voice_user_foreign_keys.rb
similarity index 91%
rename from plugins/live/db/post_migrate/20260803163818_remove_voice_user_foreign_keys.rb
rename to plugins/live/db/migrate/20260803163818_remove_voice_user_foreign_keys.rb
index 5fe95e25b1c..ec6944375b8 100644
--- a/plugins/live/db/post_migrate/20260803163818_remove_voice_user_foreign_keys.rb
+++ b/plugins/live/db/migrate/20260803163818_remove_voice_user_foreign_keys.rb
@@ -5,11 +5,15 @@
# user, memberships and co-presences removed, sessions kept as history).
class RemoveVoiceUserForeignKeys < ActiveRecord::Migration[8.0]
def up
+ Migration::SafeMigrate.disable!
+
remove_foreign_key :voice_sessions, column: :user_id, if_exists: true
remove_foreign_key :voice_room_memberships, column: :user_id, if_exists: true
remove_foreign_key :voice_co_presences, column: :user_id_1, if_exists: true
remove_foreign_key :voice_co_presences, column: :user_id_2, if_exists: true
remove_foreign_key :voice_rooms, column: :creator_id, if_exists: true
+ ensure
+ Migration::SafeMigrate.enable!
end
def down
diff --git a/plugins/live/db/post_migrate/20260824214608_drop_chat_thread_title_template_from_voice_rooms.rb b/plugins/live/db/migrate/20260824214608_drop_chat_thread_title_template_from_voice_rooms.rb
similarity index 81%
rename from plugins/live/db/post_migrate/20260824214608_drop_chat_thread_title_template_from_voice_rooms.rb
rename to plugins/live/db/migrate/20260824214608_drop_chat_thread_title_template_from_voice_rooms.rb
index 1ca95a3f283..6c4c35a73c5 100644
--- a/plugins/live/db/post_migrate/20260824214608_drop_chat_thread_title_template_from_voice_rooms.rb
+++ b/plugins/live/db/migrate/20260824214608_drop_chat_thread_title_template_from_voice_rooms.rb
@@ -4,7 +4,11 @@ class DropChatThreadTitleTemplateFromVoiceRooms < ActiveRecord::Migration[8.0]
DROPPED_COLUMNS = { voice_rooms: %i[chat_thread_title_template] }
def up
+ Migration::SafeMigrate.disable!
+
DROPPED_COLUMNS.each { |table, columns| Migration::ColumnDropper.execute_drop(table, columns) }
+ ensure
+ Migration::SafeMigrate.enable!
end
def down
diff --git a/plugins/live/db/post_migrate/20260831162602_rename_resenha_to_voice.rb b/plugins/live/db/migrate/20260831162602_rename_resenha_to_voice.rb
similarity index 97%
rename from plugins/live/db/post_migrate/20260831162602_rename_resenha_to_voice.rb
rename to plugins/live/db/migrate/20260831162602_rename_resenha_to_voice.rb
index 273b3b07fef..c956eed546e 100644
--- a/plugins/live/db/post_migrate/20260831162602_rename_resenha_to_voice.rb
+++ b/plugins/live/db/migrate/20260831162602_rename_resenha_to_voice.rb
@@ -14,6 +14,8 @@ class RenameResenhaToVoice < ActiveRecord::Migration[8.0]
}
def up
+ Migration::SafeMigrate.disable!
+
RENAMED_TABLES.each do |old_name, new_name|
rename_table(old_name, new_name) if table_exists?(old_name) && !table_exists?(new_name)
end
@@ -91,6 +93,8 @@ class RenameResenhaToVoice < ActiveRecord::Migration[8.0]
SET cooked_version = NULL
WHERE cooked LIKE '%/resenha/%'
SQL
+ ensure
+ Migration::SafeMigrate.enable!
end
def down
diff --git a/plugins/live/db/post_migrate/20260903195501_enable_voice_badges_by_default.rb b/plugins/live/db/migrate/20260903195501_enable_voice_badges_by_default.rb
similarity index 100%
rename from plugins/live/db/post_migrate/20260903195501_enable_voice_badges_by_default.rb
rename to plugins/live/db/migrate/20260903195501_enable_voice_badges_by_default.rb
diff --git a/plugins/live/db/post_migrate/20261009144947_replace_voice_video_enabled_setting.rb b/plugins/live/db/migrate/20261009144947_replace_voice_video_enabled_setting.rb
similarity index 100%
rename from plugins/live/db/post_migrate/20261009144947_replace_voice_video_enabled_setting.rb
rename to plugins/live/db/migrate/20261009144947_replace_voice_video_enabled_setting.rb
diff --git a/plugins/live/db/post_migrate/20261013160643_rename_voice_to_live.rb b/plugins/live/db/migrate/20261013160643_rename_voice_to_live.rb
similarity index 93%
rename from plugins/live/db/post_migrate/20261013160643_rename_voice_to_live.rb
rename to plugins/live/db/migrate/20261013160643_rename_voice_to_live.rb
index de4ba2c2f26..0788b2a6247 100644
--- a/plugins/live/db/post_migrate/20261013160643_rename_voice_to_live.rb
+++ b/plugins/live/db/migrate/20261013160643_rename_voice_to_live.rb
@@ -67,14 +67,25 @@ class RenameVoiceToLive < ActiveRecord::Migration[8.0]
].to_h { |name| [name, name.sub(/\Avoice_/, "live_")] }
def up
- RENAMED_TABLES.each do |old_name, new_name|
- rename_table(old_name, new_name) if table_exists?(old_name) && !table_exists?(new_name)
- end
+ Migration::SafeMigrate.disable!
+
+ renamed_tables =
+ RENAMED_TABLES.select do |old_name, new_name|
+ table_exists?(old_name) && !table_exists?(new_name)
+ end
+ renamed_tables.each { |old_name, new_name| rename_table(old_name, new_name) }
RENAMED_TABLES.each do |old_name, new_name|
rename_table_objects(old_name.to_s, new_name.to_s) if table_exists?(new_name)
end
+ # App servers still running the voice code read these until FinishRenameVoiceToLive runs.
+ renamed_tables.each do |old_name, new_name|
+ execute "CREATE VIEW #{old_name} AS SELECT * FROM #{new_name}"
+ end
+
+ Migration::SafeMigrate.enable!
+
RENAMED_SETTINGS.each do |old_name, new_name|
DB.exec(<<~SQL, old_name:, new_name:)
UPDATE site_settings
diff --git a/plugins/live/db/post_migrate/20261020161054_finish_rename_voice_to_live.rb b/plugins/live/db/post_migrate/20261020161054_finish_rename_voice_to_live.rb
new file mode 100644
index 00000000000..e38411f8d52
--- /dev/null
+++ b/plugins/live/db/post_migrate/20261020161054_finish_rename_voice_to_live.rb
@@ -0,0 +1,79 @@
+# frozen_string_literal: true
+
+class FinishRenameVoiceToLive < ActiveRecord::Migration[8.1]
+ def up
+ execute <<~SQL
+ DROP VIEW IF EXISTS
+ voice_rooms,
+ voice_room_memberships,
+ voice_sessions,
+ voice_co_presences,
+ voice_recordings,
+ voice_invites
+ SQL
+
+ # The voice code keeps writing these until its app servers restart.
+ execute <<~SQL
+ UPDATE reviewables voice
+ SET type = 'ReviewableLiveUser',
+ type_source = 'live',
+ target_type = CASE
+ WHEN target_type = 'Voice::Session' THEN 'Live::Session'
+ ELSE target_type
+ END
+ WHERE voice.type = 'ReviewableVoiceUser'
+ AND NOT EXISTS (
+ SELECT 1 FROM reviewables
+ WHERE type = 'ReviewableLiveUser' AND target_id = voice.target_id
+ )
+ SQL
+
+ execute <<~SQL if table_exists?(:chat_thread_custom_fields)
+ UPDATE chat_thread_custom_fields voice
+ SET name = 'live_room_id'
+ WHERE voice.name = 'voice_room_id'
+ AND NOT EXISTS (
+ SELECT 1 FROM chat_thread_custom_fields
+ WHERE name = 'live_room_id' AND thread_id = voice.thread_id
+ )
+ SQL
+
+ execute <<~SQL
+ UPDATE plugin_store_rows voice
+ SET plugin_name = 'live'
+ WHERE voice.plugin_name = 'voice'
+ AND NOT EXISTS (
+ SELECT 1 FROM plugin_store_rows
+ WHERE plugin_name = 'live' AND key = voice.key
+ )
+ SQL
+
+ # Seeds create an empty "Live" grouping when they run before RenameVoiceToLive.
+ execute <<~SQL
+ UPDATE badge_groupings live
+ SET position = voice.position,
+ description = COALESCE(live.description, voice.description)
+ FROM badge_groupings voice
+ WHERE live.name = 'Live' AND voice.name = 'Voice'
+ SQL
+
+ execute <<~SQL
+ UPDATE badges
+ SET badge_grouping_id = live.id
+ FROM badge_groupings voice, badge_groupings live
+ WHERE badges.badge_grouping_id = voice.id
+ AND voice.name = 'Voice'
+ AND live.name = 'Live'
+ SQL
+
+ execute <<~SQL
+ DELETE FROM badge_groupings
+ WHERE name = 'Voice'
+ AND EXISTS (SELECT 1 FROM badge_groupings WHERE name = 'Live')
+ SQL
+ end
+
+ def down
+ raise ActiveRecord::IrreversibleMigration
+ end
+end
diff --git a/plugins/live/spec/migrations/finish_rename_voice_to_live_spec.rb b/plugins/live/spec/migrations/finish_rename_voice_to_live_spec.rb
new file mode 100644
index 00000000000..2a49ea1e7b2
--- /dev/null
+++ b/plugins/live/spec/migrations/finish_rename_voice_to_live_spec.rb
@@ -0,0 +1,71 @@
+# frozen_string_literal: true
+
+require Rails.root.join(
+ "plugins/live/db/post_migrate/20261020161054_finish_rename_voice_to_live.rb",
+ )
+
+RSpec.describe FinishRenameVoiceToLive do
+ before do
+ @original_verbose = ActiveRecord::Migration.verbose
+ ActiveRecord::Migration.verbose = false
+ end
+
+ after { ActiveRecord::Migration.verbose = @original_verbose }
+
+ it "moves badges left in a Voice grouping into the existing Live grouping" do
+ live = BadgeGrouping.find_or_create_by!(name: "Live") { |g| g.position = 15 }
+ voice = BadgeGrouping.create!(name: "Voice", position: 42, description: "Calls and rooms")
+ badge = Fabricate(:badge, badge_grouping_id: voice.id)
+
+ described_class.new.up
+
+ expect(badge.reload.badge_grouping_id).to eq(live.id)
+ expect(live.reload).to have_attributes(position: 42, description: "Calls and rooms")
+ expect(BadgeGrouping.exists?(voice.id)).to eq(false)
+ end
+
+ context "with rows the voice code wrote during the deploy" do
+ fab!(:session, :live_session)
+
+ def flag_session(type, target_type)
+ reviewable = Fabricate(:reviewable)
+ DB.exec(
+ "UPDATE reviewables SET type = ?, target_type = ?, target_id = ? WHERE id = ?",
+ type,
+ target_type,
+ session.id,
+ reviewable.id,
+ )
+ reviewable.id
+ end
+
+ it "converts them to the live names" do
+ flag_id = flag_session("ReviewableVoiceUser", "Voice::Session")
+ thread = Fabricate(:chat_thread)
+ thread.upsert_custom_fields("voice_room_id" => 7)
+ PluginStore.set("voice", "livekit_agent_bot_id", 42)
+
+ described_class.new.up
+
+ expect(
+ DB.query_single(
+ "SELECT type, type_source, target_type FROM reviewables WHERE id = ?",
+ flag_id,
+ ),
+ ).to eq(%w[ReviewableLiveUser live Live::Session])
+ expect(thread.reload.custom_fields).to eq("live_room_id" => "7")
+ expect(PluginStore.get("live", "livekit_agent_bot_id")).to eq(42)
+ end
+
+ it "leaves a voice flag alone when the session already has a live one" do
+ flag_session("ReviewableLiveUser", "Live::Session")
+ voice_flag_id = flag_session("ReviewableVoiceUser", "Voice::Session")
+
+ described_class.new.up
+
+ expect(DB.query_single("SELECT type FROM reviewables WHERE id = ?", voice_flag_id)).to eq(
+ ["ReviewableVoiceUser"],
+ )
+ end
+ end
+end
diff --git a/plugins/live/spec/migrations/rename_voice_to_live_spec.rb b/plugins/live/spec/migrations/rename_voice_to_live_spec.rb
index 805a19cdcdc..386a3355879 100644
--- a/plugins/live/spec/migrations/rename_voice_to_live_spec.rb
+++ b/plugins/live/spec/migrations/rename_voice_to_live_spec.rb
@@ -1,6 +1,9 @@
# frozen_string_literal: true
-require Rails.root.join("plugins/live/db/post_migrate/20261013160643_rename_voice_to_live.rb")
+require Rails.root.join("plugins/live/db/migrate/20261013160643_rename_voice_to_live.rb")
+require Rails.root.join(
+ "plugins/live/db/post_migrate/20261020161054_finish_rename_voice_to_live.rb",
+ )
RSpec.describe RenameVoiceToLive do
before do
@@ -19,7 +22,10 @@ RSpec.describe RenameVoiceToLive do
SQL
end
- after { ActiveRecord::Migration.verbose = @original_verbose }
+ after do
+ ActiveRecord::Migration.verbose = @original_verbose
+ Migration::SafeMigrate.disable!
+ end
def relation_names(pattern)
DB.query_single("SELECT relname FROM pg_class WHERE relname ~ ?", pattern)
@@ -28,7 +34,9 @@ RSpec.describe RenameVoiceToLive do
it "renames the tables and their custom-named indexes and constraints" do
described_class.new.up
- expect(relation_names("^voice_")).to be_empty
+ expect(relation_names("^voice_")).to match_array(
+ described_class::RENAMED_TABLES.keys.map(&:to_s),
+ )
expect(relation_names("^live_")).to include(*described_class::RENAMED_TABLES.values.map(&:to_s))
expect(relation_names("^idx_live_sessions_orphaned$")).to be_present
expect(
@@ -38,6 +46,21 @@ RSpec.describe RenameVoiceToLive do
).to be_present
end
+ it "leaves views under the old table names until the post-deploy migration drops them" do
+ described_class.new.up
+
+ expect(
+ DB.query_single("SELECT relname FROM pg_class WHERE relname ~ '^voice_' AND relkind = 'v'"),
+ ).to match_array(described_class::RENAMED_TABLES.keys.map(&:to_s))
+
+ room = Fabricate(:live_room)
+ expect(DB.query_single("SELECT name FROM voice_rooms WHERE id = ?", room.id)).to eq([room.name])
+
+ FinishRenameVoiceToLive.new.up
+
+ expect(relation_names("^voice_")).to be_empty
+ end
+
it "renames the tables' triggers and the functions they call" do
DB.exec(<<~SQL)
CREATE FUNCTION raise_voice_sessions_readonly() RETURNS trigger AS $$