Kouhei Sutou
null+****@clear*****
Tue Mar 7 17:54:15 JST 2017
Kouhei Sutou 2017-03-07 17:54:15 +0900 (Tue, 07 Mar 2017) New Revision: 5908d6d3ac94945889095f23c4129973dd56fe9c https://github.com/ranguba/groonga-client-model/commit/5908d6d3ac94945889095f23c4129973dd56fe9c Message: migration: support copy_column Modified files: lib/groonga_client_model/migration.rb test/unit/migration/test_copy.rb Modified: lib/groonga_client_model/migration.rb (+20 -0) =================================================================== --- lib/groonga_client_model/migration.rb 2017-03-07 17:48:57 +0900 (e6cc4f4) +++ lib/groonga_client_model/migration.rb 2017-03-07 17:54:15 +0900 (b0f7c54) @@ -204,6 +204,26 @@ module GroongaClientModel end end + def copy_column(from_full_column_name, + to_full_column_name) + if @reverting + message = "can't revert copy_column" + message << "(#{from_full_column_name}, #{to_full_column_name})" + raise IrreversibleMigrationError, message + end + + from_table_name, from_column_name = from_full_column_name.split(".", 2) + to_table_name, to_column_name = to_full_column_name.split(".", 2) + report(__method__, [from_full_column_name, to_full_column_name]) do + @client.request(:column_copy). + parameter(:from_table, from_table_name). + parameter(:from_name, from_column_name). + parameter(:to_table, to_table_name). + parameter(:to_name, to_column_name). + response + end + end + def set_config(key, value) if @reverting message = "can't revert set_config(#{key.inspect}, #{value.inspect})" Modified: test/unit/migration/test_copy.rb (+36 -0) =================================================================== --- test/unit/migration/test_copy.rb 2017-03-07 17:48:57 +0900 (7710d7c) +++ test/unit/migration/test_copy.rb 2017-03-07 17:54:15 +0900 (e6007f5) @@ -78,4 +78,40 @@ load --table posts end end end + + test("#copy_column") do + expected_up_report = <<-REPORT +-- copy_column("posts.content", "entries.content") + -> 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","Very good!"], +["Ruby","Very exciting!"] +] + +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_column("posts.content", "entries.content") + end + end + end end -------------- next part -------------- HTML����������������������������... Télécharger