Currently, we return a 503 when the site is in maintence mode for import/export:
def block_if_maintenance_mode
if Discourse.maintenance_mode?
if request.format.json?
render status: 503, json: failed_json.merge(message: I18n.t('site_under_maintenance'))
else
render status: 503, file: File.join( Rails.root, 'public', '503.html' ), layout: false
end
end
end
Ideally, all the json calls will handle this response and do… something. If you were composing something and the response is a 503, then it can become a mess. What happens to the draft? If an export is happening, then no big deal. Wait and submit again (wait how long?). If an import is happening, the topic you’re replying to could be gone. The 503 may need to return some extra fields so that the composer can give useful advice. “Please copy your post out of the composer and save it for later” or “The site will return soon. Please submit again in 5 minutes.”
This is a difficult problem… I took a stab at it with the import adapters, but it’s a lot of work. Whenever someone adds a migration, they would often need to write an import adapter. Here’s an example:
module Import
module Adapter
class RemoveSubTagFromTopics < Base
register version: '20130116151829', tables: [:topics]
def up_column_names(table_name, column_names)
# remove_column :topics, :sub_tag
if table_name.to_sym == :topics
column_names.reject {|col| col == 'sub_tag'}
else
column_names
end
end
def up_row(table_name, row)
# remove_column :topics, :sub_tag
if table_name.to_sym == :topics
row[0..29] + row[31..-1]
else
row
end
end
end
end
end
Yuck. A simple adapter like this for remove_column
could probably be generated. But there must be a better solution.
The export file contains the metadata about where it came from, including the last migration that was run on its database (ActiveRecord::Migrator.current_version
). Could we create a database, migrate it to that version, run the import, and then migrate it to the latest version? Then we end up with two databases. They would need to be swapped or merged… Umm… Not sure.