DEV: Auto link video placeholder posts (#24576)

* DEV: Auto link video placeholder posts

Followup to 91232847e3

Adds a migration to auto-link any video placeholder posts so that upload
references will be created.

Co-authored-by: Jarek Radosz <jradosz@gmail.com>
This commit is contained in:
Blake Erickson 2023-11-27 13:22:42 -07:00 committed by GitHub
parent 6f3b087907
commit 52617e7425
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,36 @@
# frozen_string_literal: true
class TriggerAutoLinkingForVideosSincePlaceholder < ActiveRecord::Migration[7.0]
disable_ddl_transaction!
def up
# Rebake any existing video placeholder posts to ensure they are auto-linked
# to post uploads
max_id = DB.query_single(<<~SQL).first.to_i
SELECT MAX(id)
FROM posts
SQL
chunk_size = 100_000
while max_id > 0
ids = DB.query_single(<<~SQL, start: max_id - chunk_size, finish: max_id)
SELECT id
FROM posts
WHERE cooked LIKE '%video-placeholder-container%'
AND id > :start AND id <= :finish
SQL
DB.exec(<<~SQL, ids: ids) if ids && ids.length > 0
UPDATE posts
SET baked_version = NULL
WHERE id IN (:ids)
SQL
max_id -= chunk_size
end
end
def down
raise ActiveRecord::IrreversibleMigration
end
end