F #3530: add command to create FTS idx (#3671)

(cherry picked from commit eb54b9b501)
This commit is contained in:
Alejandro Huertas Herrero authored and Ruben S. Montero committed 2019-09-09 19:50:43 +02:00
1 parent c61b42c132
commit a3b5bda668
3 files changed
+53

No files matched your search

+25
View File
@@ -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
+11
View File
@@ -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()
+17
View File
@@ -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