Add virtual md5 column to external_api_images

This commit is contained in:
Donovan Daniels 2025-01-11 21:36:35 -06:00
parent 58c0cd8983
commit 9e4b59b665
No known key found for this signature in database
GPG Key ID: 743DAAE6359EDBA1
2 changed files with 19 additions and 1 deletions

View File

@ -0,0 +1,15 @@
class AddExternalAPIImagesGeneratedMd5ColumnAndSiteIndex < ActiveRecord::Migration[7.1]
def change
add_index(:external_api_images, :site)
reversible do |r|
r.up do
exec_query("ALTER TABLE external_api_images ADD COLUMN md5 TEXT GENERATED ALWAYS AS (cached_data->'file'->>'md5') STORED")
add_index(:external_api_images, :md5)
end
r.down do
exec_query("ALTER TABLE external_api_images DROP COLUMN md5")
remove_index(:external_api_images, :md5)
end
end
end
end

5
db/schema.rb generated
View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2024_10_21_212746) do ActiveRecord::Schema[7.1].define(version: 2025_01_12_032852) do
create_schema "e621" create_schema "e621"
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
@ -157,7 +157,10 @@ ActiveRecord::Schema[7.1].define(version: 2024_10_21_212746) do
t.datetime "cache_last_updated_at", default: -> { "CURRENT_TIMESTAMP(3)" }, null: false t.datetime "cache_last_updated_at", default: -> { "CURRENT_TIMESTAMP(3)" }, null: false
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
r t.virtual "md5", type: :text, as: "((cached_data -> 'file'::text) ->> 'md5'::text)", stored: true
t.index ["api_image_id"], name: "index_external_api_images_on_api_image_id" t.index ["api_image_id"], name: "index_external_api_images_on_api_image_id"
t.index ["md5"], name: "index_external_api_images_on_md5"
t.index ["site"], name: "index_external_api_images_on_site"
end end
create_table "good_job_batches", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| create_table "good_job_batches", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|