[Groonga-commit] ranguba/groonga-client-model at 67b92f1 [master] migration: support timestamps

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Mar 7 20:00:25 JST 2017


Kouhei Sutou	2017-03-07 20:00:25 +0900 (Tue, 07 Mar 2017)

  New Revision: 67b92f151ef516729c11b7343ac7934356a509a3
  https://github.com/ranguba/groonga-client-model/commit/67b92f151ef516729c11b7343ac7934356a509a3

  Message:
    migration: support timestamps

  Modified files:
    lib/groonga_client_model/migration.rb
    test/unit/migration/test_create_table.rb

  Modified: lib/groonga_client_model/migration.rb (+14 -0)
===================================================================
--- lib/groonga_client_model/migration.rb    2017-03-07 19:15:25 +0900 (1ba80cd)
+++ lib/groonga_client_model/migration.rb    2017-03-07 20:00:25 +0900 (270960d)
@@ -204,6 +204,16 @@ module GroongaClientModel
       end
     end
 
+    def add_timestamp_columns(table_name)
+      add_column(table_name, :created_at, :time)
+      add_column(table_name, :updated_at, :time)
+    end
+
+    def remove_timestamp_columns(table_name)
+      remove_column(table_name, :updated_at)
+      remove_column(table_name, :created_at)
+    end
+
     def copy_column(from_full_column_name,
                     to_full_column_name)
       if @reverting
@@ -449,6 +459,10 @@ module GroongaClientModel
                               options)
       end
 
+      def timestamps
+        @migration.add_timestamp_columns(@table_name)
+      end
+
       def index(source_table_name, source_column_names, options={})
         source_column_names = Array(source_column_names)
         column_name = [source_table_name, *source_column_names].join("_")

  Modified: test/unit/migration/test_create_table.rb (+31 -0)
===================================================================
--- test/unit/migration/test_create_table.rb    2017-03-07 19:15:25 +0900 (14b6672)
+++ test/unit/migration/test_create_table.rb    2017-03-07 20:00:25 +0900 (94f9ce4)
@@ -363,6 +363,37 @@ column_create posts #{column_name} #{flags.join("|")} #{reference_table_name}
       end
     end
 
+    sub_test_case("#timestamps") do
+      test("default") do
+        expected_up_report = <<-REPORT
+-- create_table(:posts, {:type=>"TABLE_NO_KEY"})
+   -> 0.0s
+-- add_column(:posts, :created_at, {:flags=>["COLUMN_SCALAR"], :value_type=>"Time"})
+   -> 0.0s
+-- add_column(:posts, :updated_at, {:flags=>["COLUMN_SCALAR"], :value_type=>"Time"})
+   -> 0.0s
+        REPORT
+        expected_down_report = <<-REPORT
+-- remove_table(:posts)
+   -> 0.0s
+        REPORT
+        expected_dump = <<-DUMP.chomp
+table_create posts TABLE_NO_KEY
+column_create posts created_at COLUMN_SCALAR Time
+column_create posts updated_at COLUMN_SCALAR Time
+        DUMP
+        assert_migrate(expected_up_report,
+                       expected_down_report,
+                       expected_dump) do |migration|
+          migration.instance_eval do
+            create_table(:posts) do |table|
+              table.timestamps
+            end
+          end
+        end
+      end
+    end
+
     sub_test_case("#index") do
       test("for full text search") do
         expected_up_report = <<-REPORT
-------------- next part --------------
HTML����������������������������...
Download 



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