#9 Active Storage - migration - updated_at
This commit is contained in:
parent
bf17ddc7da
commit
e9450f9a5d
@ -22,6 +22,11 @@ class ActiveStorageMigration < ActiveRecord::Migration[7.0]
|
|||||||
# File system -> Active Storage
|
# File system -> Active Storage
|
||||||
def up
|
def up
|
||||||
$stdout.puts 'It could be a very long process. Be patient...'
|
$stdout.puts 'It could be a very long process. Be patient...'
|
||||||
|
# We need to keep updated_at column unchanged and due to the asynchronous file analysis there is probably no better
|
||||||
|
# way how to achieve that.
|
||||||
|
add_column :dmsf_file_revisions, :temp_updated_at, :datetime, default: nil,
|
||||||
|
null: true, if_not_exists: true
|
||||||
|
DmsfFileRevision.update_all 'temp_updated_at = updated_at'
|
||||||
# Remove the Xapian database as it will be rebuilt from scratch during the migration
|
# Remove the Xapian database as it will be rebuilt from scratch during the migration
|
||||||
if xapian_database_removed?
|
if xapian_database_removed?
|
||||||
$stdout.puts 'The Xapian database has been removed as it will be rebuilt from scratch during the migration'
|
$stdout.puts 'The Xapian database has been removed as it will be rebuilt from scratch during the migration'
|
||||||
@ -72,7 +77,10 @@ class ActiveStorageMigration < ActiveRecord::Migration[7.0]
|
|||||||
$stdout.puts "#{File.join(key[0..1], key[2..3], key)} (#{a.blob.filename}) => #{new_path}"
|
$stdout.puts "#{File.join(key[0..1], key[2..3], key)} (#{a.blob.filename}) => #{new_path}"
|
||||||
end
|
end
|
||||||
# Remove the original file
|
# Remove the original file
|
||||||
a.blob.purge
|
r.record_timestamps = false # Do not modify updated_at column
|
||||||
|
DmsfFileRevision.no_touching do
|
||||||
|
a.purge
|
||||||
|
end
|
||||||
end
|
end
|
||||||
# Remove the Xapian database as it is useless now and has to be rebuilt with xapian_indexer.rb
|
# Remove the Xapian database as it is useless now and has to be rebuilt with xapian_indexer.rb
|
||||||
if xapian_database_removed?
|
if xapian_database_removed?
|
||||||
|
|||||||
27
db/migrate/20251017101001_restore_updated_at.rb
Normal file
27
db/migrate/20251017101001_restore_updated_at.rb
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# Redmine plugin for Document Management System "Features"
|
||||||
|
#
|
||||||
|
# Karel Pičman <karel.picman@kontron.com>
|
||||||
|
#
|
||||||
|
# This file is part of Redmine DMSF plugin.
|
||||||
|
#
|
||||||
|
# Redmine DMSF plugin is free software: you can redistribute it and/or modify it under the terms of the GNU General
|
||||||
|
# Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
|
||||||
|
# later version.
|
||||||
|
#
|
||||||
|
# Redmine DMSF plugin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
# more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License along with Redmine DMSF plugin. If not, see
|
||||||
|
# <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Restore DmsfFileRevision.updated_at from DmsfFileRevision.temp_updated_at column
|
||||||
|
class RestoreUpdatedAt < ActiveRecord::Migration[7.0]
|
||||||
|
# temp_updated_at => updated_at
|
||||||
|
def up
|
||||||
|
DmsfFileRevision.update_all 'updated_at = temp_updated_at'
|
||||||
|
remove_column :dmsf_file_revisions, :temp_updated_at
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -28,13 +28,12 @@ module RedmineDmsf
|
|||||||
end
|
end
|
||||||
|
|
||||||
def metadata
|
def metadata
|
||||||
index
|
{ xapian: indexed? }
|
||||||
{}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def index
|
def indexed?
|
||||||
stem_lang = RedmineDmsf.dmsf_stemming_lang
|
stem_lang = RedmineDmsf.dmsf_stemming_lang
|
||||||
db_path = File.join RedmineDmsf.dmsf_index_database, stem_lang
|
db_path = File.join RedmineDmsf.dmsf_index_database, stem_lang
|
||||||
url = File.join(@blob.key[0..1], @blob.key[2..3])
|
url = File.join(@blob.key[0..1], @blob.key[2..3])
|
||||||
@ -44,8 +43,10 @@ module RedmineDmsf
|
|||||||
FileUtils.mv file.path, File.join(dir, @blob.key)
|
FileUtils.mv file.path, File.join(dir, @blob.key)
|
||||||
system "omindex -s \"#{stem_lang}\" -D \"#{db_path}\" --url=/#{url} \"#{dir}\" -p", exception: true
|
system "omindex -s \"#{stem_lang}\" -D \"#{db_path}\" --url=/#{url} \"#{dir}\" -p", exception: true
|
||||||
end
|
end
|
||||||
|
true
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
Rails.logger.error e.message
|
Rails.logger.error e.message
|
||||||
|
false
|
||||||
ensure
|
ensure
|
||||||
FileUtils.rm_f dir
|
FileUtils.rm_f dir
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user