mirror of
https://github.com/discourse/discourse.git
synced 2025-10-03 17:21:20 +08:00
Post edits need to inform the backend if the locale is changed and is sometimes set as `""`. This PR prevents the locale from being set to `""` in the database, and includes a migration to purge the empty strings.
28 lines
627 B
Ruby
28 lines
627 B
Ruby
# frozen_string_literal: true
|
|
class NullifyBlankLocales < ActiveRecord::Migration[7.2]
|
|
def up
|
|
loop do
|
|
result = execute(<<~SQL)
|
|
UPDATE topics
|
|
SET locale = NULL
|
|
WHERE id IN (SELECT id FROM topics WHERE locale = '' LIMIT 5000)
|
|
SQL
|
|
|
|
break if result.cmd_tuples == 0
|
|
end
|
|
|
|
loop do
|
|
result = execute(<<~SQL)
|
|
UPDATE posts
|
|
SET locale = NULL
|
|
WHERE id IN (SELECT id FROM posts WHERE locale = '' LIMIT 5000)
|
|
SQL
|
|
|
|
break if result.cmd_tuples == 0
|
|
end
|
|
end
|
|
|
|
def down
|
|
raise ActiveRecord::IrreversibleMigration
|
|
end
|
|
end
|