discourse/db/migrate/20150112172259_migrate_site_text_to_site_customization.rb
Sam Saffron 30990006a9 DEV: enable frozen string literal on all files
This reduces chances of errors where consumers of strings mutate inputs
and reduces memory usage of the app.

Test suite passes now, but there may be some stuff left, so we will run
a few sites on a branch prior to merging
2019-05-13 09:31:32 +08:00

33 lines
797 B
Ruby

# frozen_string_literal: true
class MigrateSiteTextToSiteCustomization < ActiveRecord::Migration[4.2]
def up
execute <<-SQL
DO
$do$
BEGIN
IF EXISTS(SELECT 1 FROM site_texts WHERE (text_type = 'head' OR text_type = 'bottom')) THEN
INSERT INTO site_customizations (name, user_id, enabled, key, created_at, updated_at, head_tag, body_tag)
VALUES
(
'Migrated from Site Text',
-1,
't',
'#{SecureRandom.uuid}',
now(),
now(),
(SELECT value FROM site_texts WHERE text_type = 'head' LIMIT 1),
(SELECT value FROM site_texts WHERE text_type = 'bottom' LIMIT 1)
);
END IF;
END
$do$
SQL
end
def down
end
end