DEV: Stop compiling themes during DB migration. Recompile on cdn change. (#7676)

DEV: Stop compiling themes during DB migration. Recompile on cdn change. (#7676)

This is an improved implementation for bc8b7b13

diff --git a/app/models/theme_field.rb b/app/models/theme_field.rb
index 623df2f..9653325 100644
--- a/app/models/theme_field.rb
+++ b/app/models/theme_field.rb
@@ -64,7 +64,10 @@ class ThemeField < ActiveRecord::Base
   validates :name, format: { with: /\A[a-z_][a-z0-9_-]*\z/i },
                    if: Proc.new { |field| ThemeField.theme_var_type_ids.include?(field.type_id) }
 
-  COMPILER_VERSION = 11
+  BASE_COMPILER_VERSION = 11
+  DEPENDENT_CONSTANTS = [BASE_COMPILER_VERSION,
+                        GlobalSetting.cdn_url]
+  COMPILER_VERSION = Digest::SHA1.hexdigest(DEPENDENT_CONSTANTS.join)
 
   belongs_to :theme
 
@@ -515,7 +518,7 @@ end
 #  value_baked      :text
 #  created_at       :datetime         not null
 #  updated_at       :datetime         not null
-#  compiler_version :integer          default(0), not null
+#  compiler_version :string(50)       default("0"), not null
 #  error            :string
 #  upload_id        :integer
 #  type_id          :integer          default(0), not null
diff --git a/db/migrate/20190603134013_change_theme_field_compiler_version.rb b/db/migrate/20190603134013_change_theme_field_compiler_version.rb
new file mode 100644
index 0000000..d82a567
--- /dev/null
+++ b/db/migrate/20190603134013_change_theme_field_compiler_version.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class ChangeThemeFieldCompilerVersion < ActiveRecord::Migration[5.2]
+  def change
+    change_column(:theme_fields, :compiler_version, :string, limit: 50)
+  end
+end
diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake
index 33b2fd0..b5e4d77 100644
--- a/lib/tasks/db.rake
+++ b/lib/tasks/db.rake
@@ -42,11 +42,6 @@ task 'db:migrate' => ['environment', 'set_locale'] do |_, args|
     print "Optimizing site icons... "
     SiteIconManager.ensure_optimized!
     puts "Done"
-    puts
-    print "Recompiling theme fields... "
-    ThemeField.force_recompilation!
-    Theme.expire_site_cache!
-    puts "Done"
   end
 
   if MultisiteTestHelpers.load_multisite?

GitHub sha: 81dcadf7

1 Like

:+1: