Kouhei Sutou
null+****@clear*****
Tue Mar 7 17:48:57 JST 2017
Kouhei Sutou 2017-03-07 17:48:57 +0900 (Tue, 07 Mar 2017) New Revision: a5a3233daca380eae1fcf971febf474ef969eea0 https://github.com/ranguba/groonga-client-model/commit/a5a3233daca380eae1fcf971febf474ef969eea0 Message: migration: support copy_table Added files: test/unit/migration/test_copy.rb Modified files: lib/groonga_client_model/migration.rb test/unit/test_helper.rb Modified: lib/groonga_client_model/migration.rb (+14 -0) =================================================================== --- lib/groonga_client_model/migration.rb 2017-03-07 17:15:15 +0900 (f85f4cc) +++ lib/groonga_client_model/migration.rb 2017-03-07 17:48:57 +0900 (e6cc4f4) @@ -137,6 +137,20 @@ module GroongaClientModel end end + def copy_table(from_table_name, to_table_name) + if @reverting + message = "can't revert copy_table(#{from_table_name}, #{to_table_name})" + raise IrreversibleMigrationError, message + end + + report(__method__, [from_table_name, to_table_name]) do + @client.request(:table_copy). + parameter(:from_name, from_table_name). + parameter(:to_name, to_table_name). + response + end + end + def add_column(table_name, column_name, value_type, flags: nil, type: nil, Added: test/unit/migration/test_copy.rb (+81 -0) 100644 =================================================================== --- /dev/null +++ test/unit/migration/test_copy.rb 2017-03-07 17:48:57 +0900 (7710d7c) @@ -0,0 +1,81 @@ +# Copyright (C) 2017 Kouhei Sutou <kou �� clear-code.com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +class TestMigrationCopy < Test::Unit::TestCase + include GroongaClientModel::TestHelper + include TestHelper::Migration + + setup do + open_client do |client| + client.table_create(name: "posts", + flags: "TABLE_HASH_KEY", + key_type: "ShortText") + client.column_create(table: "posts", + name: "content", + flags: "COLUMN_SCALAR", + type: "Text") + client.table_create(name: "entries", + flags: "TABLE_PAT_KEY", + key_type: "ShortText") + client.column_create(table: "entries", + name: "content", + flags: "COLUMN_SCALAR", + type: "LongText") + values = [ + {"_key" => "Groonga", "content" => "Very good!"}, + {"_key" => "Ruby", "content" => "Very exciting!"}, + ] + client.load(table: "posts", + values: values) + end + end + + test("#copy_table") do + expected_up_report = <<-REPORT +-- copy_table(:posts, :entries) + -> 0.0s + REPORT + expected_down_report = nil + expected_dump = <<-DUMP.chomp +table_create entries TABLE_PAT_KEY ShortText +column_create entries content COLUMN_SCALAR LongText + +table_create posts TABLE_HASH_KEY ShortText +column_create posts content COLUMN_SCALAR Text + +load --table entries +[ +["_key","content"], +["Groonga",""], +["Ruby",""] +] + +load --table posts +[ +["_key","content"], +["Groonga","Very good!"], +["Ruby","Very exciting!"] +] + DUMP + assert_migrate(expected_up_report, + expected_down_report, + expected_dump) do |migration| + migration.instance_eval do + copy_table(:posts, :entries) + end + end + end +end Modified: test/unit/test_helper.rb (+3 -1) =================================================================== --- test/unit/test_helper.rb 2017-03-07 17:15:15 +0900 (878bb0f) +++ test/unit/test_helper.rb 2017-03-07 17:48:57 +0900 (ca435fa) @@ -49,6 +49,8 @@ module TestHelper end end + original_dump = dump + up_output = StringIO.new open_client do |client| migration = migration_class.new(client) @@ -67,7 +69,7 @@ module TestHelper migration.down end assert_equal(expected_down_report, normalize_report(down_output.string)) - assert_equal("", dump) + assert_equal(original_dump, dump) else open_client do |client| migration = migration_class.new(client) -------------- next part -------------- HTML����������������������������...Download