From 9156d6cd9d9f6f0c94f1a350cc50559b6f6216df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Fri, 7 Aug 2015 16:30:30 +0200 Subject: [PATCH] FIX: only migrate SiteText to SiteCustomization if there are any --- ...migrate_site_text_to_site_customization.rb | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/db/migrate/20150112172259_migrate_site_text_to_site_customization.rb b/db/migrate/20150112172259_migrate_site_text_to_site_customization.rb index 569f4b98b2a..4e3b18fe730 100644 --- a/db/migrate/20150112172259_migrate_site_text_to_site_customization.rb +++ b/db/migrate/20150112172259_migrate_site_text_to_site_customization.rb @@ -2,18 +2,25 @@ class MigrateSiteTextToSiteCustomization < ActiveRecord::Migration def up execute <<-SQL - 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) - ) + 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