From 1c9b5e75e7343dc15b0ca9cc44608cb047b4a942 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Tue, 9 Oct 2018 13:11:45 +0800 Subject: [PATCH] DEV: Support post deployment migrations for plugins. --- config/initializers/000-post_migration.rb | 2 +- lib/discourse.rb | 4 ++++ lib/plugin/instance.rb | 7 ++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/config/initializers/000-post_migration.rb b/config/initializers/000-post_migration.rb index 1afb441cc20..acff3e26d9f 100644 --- a/config/initializers/000-post_migration.rb +++ b/config/initializers/000-post_migration.rb @@ -1,4 +1,4 @@ -unless ['1', 'true'].include?(ENV["SKIP_POST_DEPLOYMENT_MIGRATIONS"]&.to_s) +unless Discourse.skip_post_deployment_migrations? Rails.application.config.paths['db/migrate'] << Rails.root.join( Discourse::DB_POST_MIGRATE_PATH ).to_s diff --git a/lib/discourse.rb b/lib/discourse.rb index ee09328ad80..eb529bd401d 100644 --- a/lib/discourse.rb +++ b/lib/discourse.rb @@ -649,4 +649,8 @@ module Discourse ENV["DISCOURSE_RUNNING_IN_RACK"] == "1" end + def self.skip_post_deployment_migrations? + ['1', 'true'].include?(ENV["SKIP_POST_DEPLOYMENT_MIGRATIONS"]&.to_s) + end + end diff --git a/lib/plugin/instance.rb b/lib/plugin/instance.rb index 21c4b82d88c..bc198b39326 100644 --- a/lib/plugin/instance.rb +++ b/lib/plugin/instance.rb @@ -460,7 +460,12 @@ class Plugin::Instance Rake.add_rakelib(File.dirname(path) + "/lib/tasks") # Automatically include migrations - Rails.configuration.paths["db/migrate"] << File.dirname(path) + "/db/migrate" + migration_paths = Rails.configuration.paths["db/migrate"] + migration_paths << File.dirname(path) + "/db/migrate" + + unless Discourse.skip_post_deployment_migrations? + migration_paths << "#{File.dirname(path)}/#{Discourse::DB_POST_MIGRATE_PATH}" + end public_data = File.dirname(path) + "/public" if Dir.exists?(public_data)