Kouhei Sutou
null+****@clear*****
Fri Mar 3 21:00:32 JST 2017
Kouhei Sutou 2017-03-03 21:00:32 +0900 (Fri, 03 Mar 2017) New Revision: 1eb6d7835d38a6d7226e4d3cab57d1d6ca093ad9 https://github.com/ranguba/groonga-client-model/commit/1eb6d7835d38a6d7226e4d3cab57d1d6ca093ad9 Message: Support setup schema by migration on test Added files: test/apps/rails5/db/groonga/migrate/20170301061420_create_posts.rb test/apps/rails5/db/groonga/migrate/20170303115054_create_terms.rb test/apps/rails5/db/groonga/migrate/20170303115135_create_ages.rb Removed files: test/apps/rails5/db/schema.grn Modified files: lib/groonga_client_model/migrator.rb lib/groonga_client_model/schema_loader.rb lib/groonga_client_model/test/groonga_server_runner.rb test/apps/rails5/Gemfile.lock Modified: lib/groonga_client_model/migrator.rb (+12 -0) =================================================================== --- lib/groonga_client_model/migrator.rb 2017-03-03 20:48:37 +0900 (34d6e55) +++ lib/groonga_client_model/migrator.rb 2017-03-03 21:00:32 +0900 (42ac196) @@ -24,7 +24,10 @@ module GroongaClientModel end end + attr_accessor :output + def initialize(search_paths, target_version) + @output = nil @search_paths = Array(search_paths) @target_version = target_version ensure_versions @@ -35,6 +38,7 @@ module GroongaClientModel each do |definition| Client.open do |client| migration = definition.create_migration(client) + migration.output = @output report(definition) do if forward? migration.up @@ -74,6 +78,14 @@ module GroongaClientModel end private + def puts(*args) + if @output + @output.puts(*args) + else + super + end + end + def version_table_name "schema_versions" end Modified: lib/groonga_client_model/schema_loader.rb (+3 -6) =================================================================== --- lib/groonga_client_model/schema_loader.rb 2017-03-03 20:48:37 +0900 (a82d322) +++ lib/groonga_client_model/schema_loader.rb 2017-03-03 21:00:32 +0900 (bc642d1) @@ -18,20 +18,17 @@ require "groonga/command/parser" module GroongaClientModel class SchemaLoader - def initialize(base_dir) - @base_dir = base_dir + def initialize(schema_path) + @schema_path = schema_path end def load - schema_path = @base_dir + "db" + "schema.grn" - return unless schema_path.exist? - Client.open do |client| parser = Groonga::Command::Parser.new parser.on_command do |command| client.execute(command) end - schema_path.open do |schema_file| + @schema_path.open do |schema_file| schema_file.each_line do |line| parser << line end Modified: lib/groonga_client_model/test/groonga_server_runner.rb (+15 -2) =================================================================== --- lib/groonga_client_model/test/groonga_server_runner.rb 2017-03-03 20:48:37 +0900 (aa3c920) +++ lib/groonga_client_model/test/groonga_server_runner.rb 2017-03-03 21:00:32 +0900 (66b78b4) @@ -16,10 +16,13 @@ require "pathname" require "socket" +require "stringio" require "uri" require "groonga/client/test/groonga-server-runner" +require "groonga_client_model/migrator" + module GroongaClientModel module Test class GroongaServerRunner < Groonga::Client::Test::GroongaServerRunner @@ -37,8 +40,18 @@ module GroongaClientModel else base_dir = Pathname.pwd end - schema_loader = SchemaLoader.new(base_dir) - schema_loader.load + + schema_path = base_dir + "db" + "schema.grn" + if schema_path.exist? + schema_loader = SchemaLoader.new(base_dir) + schema_loader.load + else + output = StringIO.new + migrator = Migrator.new(base_dir + "db" + "groonga" + "migrate", + nil) + migrator.output = output + migrator.migrate + end end def url Modified: test/apps/rails5/Gemfile.lock (+8 -8) =================================================================== --- test/apps/rails5/Gemfile.lock 2017-03-03 20:48:37 +0900 (3ac31d2) +++ test/apps/rails5/Gemfile.lock 2017-03-03 21:00:32 +0900 (cf45abc) @@ -1,7 +1,7 @@ PATH remote: ../../../../groonga-client specs: - groonga-client (0.4.1) + groonga-client (0.4.2) gqtp (>= 1.0.4) groonga-command (>= 1.2.8) groonga-command-parser (>= 1.0.7) @@ -10,9 +10,9 @@ PATH PATH remote: ../../../ specs: - groonga-client-model (0.9.9) + groonga-client-model (1.0.1) activemodel - groonga-client (>= 0.4.1) + groonga-client (>= 0.4.2) groonga-command-parser GEM @@ -78,12 +78,12 @@ GEM globalid (0.3.7) activesupport (>= 4.1.0) gqtp (1.0.6) - groonga-command (1.3.1) + groonga-command (1.3.2) json - groonga-command-parser (1.0.7) - groonga-command (>= 1.0.9) + groonga-command-parser (1.0.9) + groonga-command (>= 1.3.2) json-stream - hashie (3.4.6) + hashie (3.5.5) i18n (0.7.0) jbuilder (2.6.1) activesupport (>= 3.0.0, < 5.1) @@ -92,7 +92,7 @@ GEM rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - json (2.0.2) + json (2.0.3) json-stream (0.2.1) listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) Added: test/apps/rails5/db/groonga/migrate/20170301061420_create_posts.rb (+8 -0) 100644 =================================================================== --- /dev/null +++ test/apps/rails5/db/groonga/migrate/20170301061420_create_posts.rb 2017-03-03 21:00:32 +0900 (5373899) @@ -0,0 +1,8 @@ +class CreatePosts < GroongaClientModel::Migration + def change + create_table :posts do |t| + t.short_text :title + t.text :body + end + end +end Added: test/apps/rails5/db/groonga/migrate/20170303115054_create_terms.rb (+7 -0) 100644 =================================================================== --- /dev/null +++ test/apps/rails5/db/groonga/migrate/20170303115054_create_terms.rb 2017-03-03 21:00:32 +0900 (8027534) @@ -0,0 +1,7 @@ +class CreateTerms < GroongaClientModel::Migration + def change + create_table :terms, propose: :full_text_search do |t| + t.index :posts, :body + end + end +end Added: test/apps/rails5/db/groonga/migrate/20170303115135_create_ages.rb (+6 -0) 100644 =================================================================== --- /dev/null +++ test/apps/rails5/db/groonga/migrate/20170303115135_create_ages.rb 2017-03-03 21:00:32 +0900 (22b513c) @@ -0,0 +1,6 @@ +class CreateAges < GroongaClientModel::Migration + def change + create_table :ages, type: :hash_table, key_type: :uint32 do |t| + end + end +end Deleted: test/apps/rails5/db/schema.grn (+0 -11) 100644 =================================================================== --- test/apps/rails5/db/schema.grn 2017-03-03 20:48:37 +0900 (73c86b5) +++ /dev/null @@ -1,11 +0,0 @@ -table_create posts TABLE_NO_KEY - -column_create posts title COLUMN_SCALAR ShortText -column_create posts body COLUMN_SCALAR Text - -table_create terms TABLE_PAT_KEY ShortText \ - --default_tokenizer TokenBigram \ - --normalizer NormalizerAuto -column_create terms posts_body COLUMN_INDEX|WITH_POSITION posts body - -table_create ages TABLE_HASH_KEY UInt32 -------------- next part -------------- HTML����������������������������...Download