Files
redux-scraper/db/migrate/20250723194407_migrate_e621_post_data_to_aux.rb
2025-07-26 00:54:03 +00:00

74 lines
2.5 KiB
Ruby

# typed: strict
# frozen_string_literal: true
class MigrateE621PostDataToAux < ActiveRecord::Migration[7.2]
sig { void }
def up
execute <<~SQL
INSERT INTO domain_posts_e621_aux (
base_table_id,
state,
e621_id,
scanned_post_favs_at,
rating,
tags_array,
flags_array,
pools_array,
sources_array,
artists_array,
e621_updated_at,
parent_post_e621_id,
last_index_page_id,
caused_by_entry_id,
scan_log_entry_id,
index_page_ids,
description,
score,
score_up,
score_down,
num_favorites,
num_comments,
change_seq,
md5,
prev_md5s,
scan_error,
uploader_user_id
)
SELECT
id as base_table_id,
(json_attributes->>'state')::text as state,
(json_attributes->>'e621_id')::integer as e621_id,
(json_attributes->>'scanned_post_favs_at')::timestamp as scanned_post_favs_at,
(json_attributes->>'rating')::text as rating,
(json_attributes->>'tags_array')::jsonb as tags_array,
(json_attributes->>'flags_array')::jsonb as flags_array,
(json_attributes->>'pools_array')::jsonb as pools_array,
(json_attributes->>'sources_array')::jsonb as sources_array,
(json_attributes->>'artists_array')::jsonb as artists_array,
(json_attributes->>'e621_updated_at')::timestamp as e621_updated_at,
(json_attributes->>'parent_post_e621_id')::integer as parent_post_e621_id,
(json_attributes->>'last_index_page_id')::integer as last_index_page_id,
(json_attributes->>'caused_by_entry_id')::integer as caused_by_entry_id,
(json_attributes->>'scan_log_entry_id')::integer as scan_log_entry_id,
(json_attributes->>'index_page_ids')::jsonb as index_page_ids,
(json_attributes->>'description')::text as description,
(json_attributes->>'score')::integer as score,
(json_attributes->>'score_up')::integer as score_up,
(json_attributes->>'score_down')::integer as score_down,
(json_attributes->>'num_favorites')::integer as num_favorites,
(json_attributes->>'num_comments')::integer as num_comments,
(json_attributes->>'change_seq')::integer as change_seq,
(json_attributes->>'md5')::text as md5,
(json_attributes->>'prev_md5s')::jsonb as prev_md5s,
(json_attributes->>'scan_error')::text as scan_error,
(json_attributes->>'uploader_user_id')::integer as uploader_user_id
FROM domain_posts
WHERE type = 'Domain::Post::E621Post'
SQL
end
sig { void }
def down
end
end