Navigation Menu

Skip to content

Commit

Permalink
groonga: Implement column_rename command
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 23, 2014
1 parent 42dfd41 commit 6813a7c
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/droonga/plugins/groonga.rb
Expand Up @@ -30,4 +30,5 @@ module Groonga
require "droonga/plugins/groonga/table_remove"
require "droonga/plugins/groonga/column_create"
require "droonga/plugins/groonga/column_remove"
require "droonga/plugins/groonga/column_rename"

82 changes: 82 additions & 0 deletions lib/droonga/plugins/groonga/column_rename.rb
@@ -0,0 +1,82 @@
# Copyright (C) 2014 Droonga Project
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License version 2.1 as published by the Free Software Foundation.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

require "groonga/command/column-rename"

require "droonga/plugin"
require "droonga/plugins/groonga/generic_command"

module Droonga
module Plugins
module Groonga
module ColumnRename
class Command < GenericCommand
def process_request(request)
command_class = ::Groonga::Command.find("column_rename")
@command = command_class.new("column_rename", request)

table_name = @command["table"]
if table_name.nil? or @context[table_name].nil?
message = "table doesn't exist: <#{table_name.to_s}>"
raise CommandError.new(:status => Status::INVALID_ARGUMENT,
:message => message,
:result => false)
end

column_name = @command["name"]
if column_name.nil? or @context[table_name].column(column_name).nil?
message = "column doesn't exist: <#{column_name.to_s}>"
raise CommandError.new(:status => Status::INVALID_ARGUMENT,
:message => message,
:result => false)
end

rename_column
end

private
def rename_column
table_name = @command["table"]
column_name = @command["name"]
new_name = @command["new_name"]

::Groonga::Schema.define(:context => @context) do |schema|
schema.change_table(table_name) do |table|
table.rename_column(column_name, new_name)
end
end
true
end
end

class Handler < Droonga::Handler
action.synchronous = true

def handle(message)
command = Command.new(@context)
command.execute(message.request)
end
end

Groonga.define_single_step do |step|
step.name = "column_rename"
step.write = true
step.handler = Handler
step.collector = Collectors::Or
end
end
end
end
end
1 change: 1 addition & 0 deletions lib/droonga/plugins/groonga/generic_response.rb
Expand Up @@ -25,6 +25,7 @@ class Adapter < Droonga::Adapter
"table_remove",
"column_create",
"column_remove",
"column_rename",
]
input_message.pattern = ["type", :in, groonga_commands]
output_message.pattern = ["body.result", :exist]
Expand Down

0 comments on commit 6813a7c

Please sign in to comment.