mirror of
https://github.com/discourse/discourse.git
synced 2026-08-05 21:57:36 +08:00
The recompress_original_jpg_quality back-fill migration writes a redundant override row on every fresh install (the CTE's COALESCE(..., 90) maps to image_quality='90', which is also the default we want anyway). Gate the migration on Migration::Helpers.existing_site? and bump the YAML default to 90 so behaviour on a fresh install is unchanged. Extracted from https://github.com/discourse/discourse/pull/39788.
42 lines
1.1 KiB
Ruby
Vendored
42 lines
1.1 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
class PopulateImageQualitySetting < ActiveRecord::Migration[8.0]
|
|
def up
|
|
return if Migration::Helpers.new_site?
|
|
|
|
execute(<<~SQL)
|
|
WITH src AS (
|
|
SELECT
|
|
COALESCE(
|
|
CAST((
|
|
SELECT value
|
|
FROM site_settings
|
|
WHERE name = 'recompress_original_jpg_quality'
|
|
) AS INTEGER),
|
|
90
|
|
) AS recompress_quality
|
|
)
|
|
INSERT INTO site_settings (name, data_type, value, created_at, updated_at)
|
|
SELECT
|
|
'image_quality',
|
|
7,
|
|
CASE
|
|
WHEN recompress_quality BETWEEN 0 AND 60 THEN '50'
|
|
WHEN recompress_quality BETWEEN 61 AND 75 THEN '70'
|
|
WHEN recompress_quality BETWEEN 76 AND 99 THEN '90'
|
|
WHEN recompress_quality = 100 THEN '100'
|
|
ELSE '90'
|
|
END,
|
|
NOW(),
|
|
NOW()
|
|
FROM src
|
|
ON CONFLICT (name) DO UPDATE SET value = EXCLUDED.value;
|
|
SQL
|
|
end
|
|
|
|
def down
|
|
execute(<<~SQL)
|
|
DELETE FROM site_settings WHERE name = 'image_quality';
|
|
SQL
|
|
end
|
|
end
|