Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions db/migrate/20250630040849_add_index_post_locale_post_id.rb

This file was deleted.

36 changes: 36 additions & 0 deletions db/migrate/20250701042909_clear_dupes_add_index_to_post_locale.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

class ClearDupesAddIndexToPostLocale < ActiveRecord::Migration[7.2]
disable_ddl_transaction!

def up
execute <<~SQL
DELETE FROM discourse_translator_post_locales
WHERE id IN (
SELECT id
FROM (
SELECT id,
ROW_NUMBER() OVER (
PARTITION BY post_id
ORDER BY created_at DESC, id DESC
) AS rnum
FROM discourse_translator_post_locales
) t
WHERE t.rnum > 1
)
SQL

execute <<~SQL
DROP INDEX IF EXISTS index_discourse_translator_post_locales_on_post_id
SQL

execute <<~SQL
CREATE UNIQUE INDEX CONCURRENTLY index_discourse_translator_post_locales_on_post_id
ON discourse_translator_post_locales (post_id)
SQL
end

def down
raise ActiveRecord::IrreversibleMigration
end
end
Loading