Kouhei Sutou
null+****@clear*****
Mon Mar 6 11:35:59 JST 2017
Kouhei Sutou 2017-03-06 11:35:59 +0900 (Mon, 06 Mar 2017) New Revision: 893562bcc189f0c375cea0b8b55c13ef9051ce62 https://github.com/ranguba/groonga-client-model/commit/893562bcc189f0c375cea0b8b55c13ef9051ce62 Message: migration: support integer family Modified files: lib/groonga_client_model/migration.rb test/unit/migration/test_create_table.rb Modified: lib/groonga_client_model/migration.rb (+12 -0) =================================================================== --- lib/groonga_client_model/migration.rb 2017-03-06 11:28:09 +0900 (a557157) +++ lib/groonga_client_model/migration.rb 2017-03-06 11:35:59 +0900 (14d4a8a) @@ -328,6 +328,18 @@ module GroongaClientModel end alias_method :bool, :boolean + def integer(column_name, options={}) + options = options.dup + bit = options.delete(:bit) || 32 + unsigned = options.delete(:unsigned) + if unsigned + type = "uint#{bit}" + else + type = "int#{bit}" + end + @migration.add_column(@table_name, column_name, type, options) + end + def short_text(column_name, options={}) @migration.add_column(@table_name, column_name, :short_text, options) end Modified: test/unit/migration/test_create_table.rb (+64 -0) =================================================================== --- test/unit/migration/test_create_table.rb 2017-03-06 11:28:09 +0900 (52c8143) +++ test/unit/migration/test_create_table.rb 2017-03-06 11:35:59 +0900 (e0ab856) @@ -186,6 +186,70 @@ column_create posts published COLUMN_SCALAR Bool end end + sub_test_case("#integer") do + def assert_migrate_integer(type, options) + expected_up_report = <<-REPORT +-- create_table(:posts, {:type=>"TABLE_NO_KEY"}) + -> 0.0s +-- add_column(:posts, :score, {:flags=>["COLUMN_SCALAR"], :value_type=>"#{type}"}) + -> 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 score COLUMN_SCALAR #{type} + DUMP + assert_migrate(expected_up_report, + expected_down_report, + expected_dump) do |migration| + migration.instance_eval do + create_table(:posts) do |table| + table.integer(:score, options) + end + end + end + end + + test("default") do + assert_migrate_integer("Int32", {}) + end + + test("bit: 8") do + assert_migrate_integer("Int8", bit: 8) + end + + test("bit: 16") do + assert_migrate_integer("Int16", bit: 16) + end + + test("bit: 32") do + assert_migrate_integer("Int32", bit: 32) + end + + test("bit: 64") do + assert_migrate_integer("Int64", bit: 64) + end + + test("bit: 8, unsigned: true") do + assert_migrate_integer("UInt8", bit: 8, unsigned: true) + end + + test("bit: 16, unsigned: true") do + assert_migrate_integer("UInt16", bit: 16, unsigned: true) + end + + test("bit: 32, unsigned: true") do + assert_migrate_integer("UInt32", bit: 32, unsigned: true) + end + + test("bit: 64, unsigned: true") do + assert_migrate_integer("UInt64", bit: 64, unsigned: true) + end + end + sub_test_case("#short_text") do test("default") do expected_up_report = <<-REPORT -------------- next part -------------- HTML����������������������������...Download