Skip to content

Commit

Permalink
Fix a bug that database migration raises exception
Browse files Browse the repository at this point in the history
It means that we couldn't open old database with new droonga-engine. :<
  • Loading branch information
kou committed Nov 5, 2014
1 parent 7d3ec56 commit 4115072
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/droonga/catalog/version2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ def slices(node)
if volume_address.node == node
path = File.join([device, Path.databases.basename.to_s, volume_address.name, "db"])
path = Pathname(path).expand_path(base_path)
migrate_database_location(path, :device => device,
:name => volume_address.name)
migrate_database_location(device, volume_address.name)
options = {
:dataset => dataset_name,
:database => path.to_s,
Expand Down Expand Up @@ -87,11 +86,15 @@ def collect_all_nodes
nodes.sort.uniq
end

def migrate_database_location(path, params)
old_path = File.join([params[:device], params[:name], "db"])
old_path = Pathname(old_path).expand_path(base_path)
if old_path.exist? and not path.exist?
FileUtils.move(old_path.to_s, path.to_s)
def migrate_database_location(device, name)
common_base_path = Pathname(base_path) + device
old_db_dir_path = common_base_path + name
old_db_path = old_db_dir_path + "db"
current_db_dir_path = common_base_path + Path.databases.basename + name
current_db_path = current_db_dir_path + "db"
if old_db_path.exist? and not current_db_path.exist?
FileUtils.mkdir_p(current_db_dir_path.parent)
FileUtils.move(old_db_dir_path, current_db_dir_path)
end
end
end
Expand Down

0 comments on commit 4115072

Please sign in to comment.