[Groonga-commit] ranguba/groonga-client-model at 8211e60 [master] migration: fix a bug that redo doesn't work with the first version

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Mar 7 16:59:33 JST 2017


Kouhei Sutou	2017-03-07 16:59:33 +0900 (Tue, 07 Mar 2017)

  New Revision: 8211e607a0ee3f05de0dc9f7c583ffd1d4acb428
  https://github.com/ranguba/groonga-client-model/commit/8211e607a0ee3f05de0dc9f7c583ffd1d4acb428

  Message:
    migration: fix a bug that redo doesn't work with the first version

  Modified files:
    lib/groonga_client_model/migrator.rb
    test/unit/test_migrator.rb

  Modified: lib/groonga_client_model/migrator.rb (+7 -3)
===================================================================
--- lib/groonga_client_model/migrator.rb    2017-03-07 16:00:34 +0900 (f2d0216)
+++ lib/groonga_client_model/migrator.rb    2017-03-07 16:59:33 +0900 (036368e)
@@ -48,9 +48,9 @@ module GroongaClientModel
         index = step - 1
       else
         index =****@versi*****(@current_version)
-        index += step if index
+        index += step
       end
-      if index.nil? or index < 0
+      if index < 0
         version = 0
       else
         version = @versions[index]
@@ -73,7 +73,11 @@ module GroongaClientModel
               migration.down
               delete_version(client, definition.version)
               previous_version_index =****@versi*****(definition.version) - 1
-              @current_version = @versions[previous_version_index] || 0
+              if previous_version_index < 0
+                @current_version = nil
+              else
+                @current_version = @versions[previous_version_index]
+              end
             end
           end
         end

  Modified: test/unit/test_migrator.rb (+20 -2)
===================================================================
--- test/unit/test_migrator.rb    2017-03-07 16:00:34 +0900 (7cf5001)
+++ test/unit/test_migrator.rb    2017-03-07 16:59:33 +0900 (929ccb0)
@@ -121,9 +121,27 @@ class TestMigrator < Test::Unit::TestCase
                    ],
                    migrator.each.collect(&:version))
     end
+  end
+
+  sub_test_case("redo") do
+    test("first version") do
+      migrator = create_migrator
+      migrator.target_version = migrator.each.collect(&:version).first
+      migrator.migrate
+
+      migrator = create_migrator
+      migrator.step = -1
+      migrator.migrate
+      migrator.step = 1
+      assert_equal([
+                     20170301061420,
+                   ],
+                   migrator.each.collect(&:version))
+    end
 
-    test("redo") do
-      migrator = create_migrator.migrate
+    test("latest version") do
+      migrator = create_migrator
+      migrator.migrate
 
       migrator = create_migrator
       migrator.step = -1
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index