diff --git a/src/onedb/onedb b/src/onedb/onedb index a0464d665b..5818885dbd 100755 --- a/src/onedb/onedb +++ b/src/onedb/onedb @@ -73,6 +73,12 @@ FEDERATED = { :description => "Limit backup/restore to federated tables" } +RECREATE = { + :name => 'recreate', + :large => '--recreate', + :description => 'Delete FTS index and create a new one' +} + ############################################################################### # SQLite options ############################################################################### @@ -739,4 +745,23 @@ cmd=CommandParser::CmdParser.new(ARGV) do 0 # exit code end + + ########################################################################### + # Create and recreate FTS index in vmpool + ########################################################################### + fts_desc = <<-EOT.unindent + Create or recreate FTS index in vm pool to be able to search VMs + EOT + + command :'create-index', fts_desc, :options => [RECREATE] do + begin + helper = OneDB.new(options) + helper.fts_index(options.has_key? :recreate) + rescue StandardError => e + STDERR.puts e.message + [-1, e.message] + end + + 0 + end end diff --git a/src/onedb/onedb.rb b/src/onedb/onedb.rb index b3fcc0b731..782a6f4b82 100644 --- a/src/onedb/onedb.rb +++ b/src/onedb/onedb.rb @@ -505,6 +505,17 @@ class OneDB end end + # Create or recreate FTS index on vm_pool search_token column + # + # @param recreate [Boolean] True to delete the index and create it again + def fts_index(recreate = false) + if backend.is_a? BackEndSQLite + raise 'This is operation is not supported for sqlite backend' + end + + backend.fts_index(recreate) + end + private def one_not_running() diff --git a/src/onedb/onedb_backend.rb b/src/onedb/onedb_backend.rb index f5c410ea67..73a05fa081 100644 --- a/src/onedb/onedb_backend.rb +++ b/src/onedb/onedb_backend.rb @@ -296,6 +296,23 @@ class BackEndMySQL < OneDBBacKEnd puts "MySQL DB #{@db_name} at #{@server} restored." end + # Create or recreate FTS index on vm_pool search_token column + # + # @param recreate [Boolean] True to delete the index and create it again + def fts_index(recreate = false) + connect_db + + if recreate + @db.alter_table(:vm_pool) do + drop_index :search_token, name: 'ftidx' + end + end + + @db.alter_table(:vm_pool) do + add_full_text_index :search_token, name: 'ftidx' + end + end + private def connect_db