groonga-client-model 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/text/news.md +30 -0
- data/groonga-client-model.gemspec +1 -1
- data/lib/groonga_client_model/log_subscriber.rb +1 -3
- data/lib/groonga_client_model/migration.rb +493 -0
- data/lib/groonga_client_model/migrator.rb +240 -0
- data/lib/groonga_client_model/railtie.rb +4 -2
- data/lib/groonga_client_model/railties/groonga.rake +55 -2
- data/lib/groonga_client_model/record.rb +39 -1
- data/lib/groonga_client_model/schema.rb +8 -0
- data/lib/groonga_client_model/schema_loader.rb +4 -9
- data/lib/groonga_client_model/test/groonga_server_runner.rb +19 -3
- data/lib/groonga_client_model/version.rb +1 -1
- data/lib/rails/generators/groonga_client_model/migration/templates/create_table_migration.rb +14 -0
- data/lib/rails/generators/groonga_client_model/migration/templates/delete_config_migration.rb +9 -0
- data/lib/rails/generators/groonga_client_model/migration/templates/migration.rb +12 -0
- data/lib/rails/generators/groonga_client_model/migration/templates/set_config_migration.rb +10 -0
- data/lib/rails/generators/groonga_client_model/migration_generator.rb +125 -0
- data/lib/rails/generators/groonga_client_model/{model/model_generator.rb → model_generator.rb} +18 -4
- data/test/apps/rails4/Gemfile.lock +2 -2
- data/test/apps/rails4/db/groonga/migrate/20170303120517_create_posts.rb +8 -0
- data/test/apps/rails4/db/groonga/migrate/20170303120527_create_terms.rb +7 -0
- data/test/apps/rails4/db/groonga/migrate/20170303120536_create_ages.rb +6 -0
- data/test/apps/rails4/log/development.log +22 -0
- data/test/apps/rails4/log/test.log +1350 -0
- data/test/apps/rails4/test/generators/migration_generator_test.rb +103 -0
- data/test/apps/rails4/test/tmp/db/groonga/migrate/20170307045825_set_config_alias_column.rb +10 -0
- data/test/apps/rails5/Gemfile.lock +8 -8
- data/test/apps/rails5/db/groonga/migrate/20170301061420_create_posts.rb +8 -0
- data/test/apps/rails5/db/groonga/migrate/20170303115054_create_terms.rb +7 -0
- data/test/apps/rails5/db/groonga/migrate/20170303115135_create_ages.rb +6 -0
- data/test/apps/rails5/log/development.log +350 -0
- data/test/apps/rails5/log/test.log +3260 -0
- data/test/apps/rails5/test/generators/migration_generator_test.rb +103 -0
- data/test/apps/rails5/test/tmp/db/groonga/migrate/20170307081511_remove_title_from_posts.rb +5 -0
- data/test/apps/rails5/tmp/cache/assets/sprockets/v3.0/5C/5Cws9GLWcOju_f3tIpY01qSaj7zkLAU0a2bQmpf7sS8.cache +1 -0
- data/test/apps/rails5/tmp/cache/assets/sprockets/v3.0/XH/XH9pWZvGgK476BpPGID5z8hjzRmGJjtzV0cHBLXhIKc.cache +1 -0
- data/test/unit/fixtures/migrate/20170301061420_create_posts.rb +8 -0
- data/test/unit/fixtures/migrate/20170303115054_create_terms.rb +7 -0
- data/test/unit/fixtures/migrate/20170303115135_create_ages.rb +6 -0
- data/test/unit/migration/test_config.rb +62 -0
- data/test/unit/migration/test_copy.rb +117 -0
- data/test/unit/migration/test_create_table.rb +528 -0
- data/test/unit/migration/test_exist.rb +47 -0
- data/test/unit/migration/test_load.rb +83 -0
- data/test/unit/record/test_active_model.rb +31 -0
- data/test/unit/record/test_readers.rb +45 -0
- data/test/unit/record/test_timestamps.rb +76 -0
- data/test/unit/record/test_validators.rb +295 -0
- data/test/unit/run-test.rb +1 -2
- data/test/unit/test_helper.rb +109 -0
- data/test/unit/test_load_value_generator.rb +8 -7
- data/test/unit/test_migrator.rb +156 -0
- metadata +64 -11
- data/test/apps/rails4/db/schema.grn +0 -9
- data/test/apps/rails5/db/schema.grn +0 -11
- data/test/unit/test_record.rb +0 -345
@@ -0,0 +1,103 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "rails/generators/groonga_client_model/migration_generator"
|
3
|
+
|
4
|
+
class MigrationGeneratorTest < Rails::Generators::TestCase
|
5
|
+
tests GroongaClientModel::Generators::MigrationGenerator
|
6
|
+
destination File.expand_path("../tmp", __dir__)
|
7
|
+
setup :prepare_destination
|
8
|
+
|
9
|
+
test "add_column" do
|
10
|
+
run_generator(["add_title_to_posts", "title:short_text"])
|
11
|
+
assert_migration("db/groonga/migrate/add_title_to_posts.rb", <<-MIGRATION)
|
12
|
+
class AddTitleToPosts < GroongaClientModel::Migration
|
13
|
+
def change
|
14
|
+
add_column :posts, :title, :short_text
|
15
|
+
end
|
16
|
+
end
|
17
|
+
MIGRATION
|
18
|
+
end
|
19
|
+
|
20
|
+
test "remove_column" do
|
21
|
+
run_generator(["remove_title_from_posts", "title"])
|
22
|
+
assert_migration("db/groonga/migrate/remove_title_from_posts.rb", <<-MIGRATION)
|
23
|
+
class RemoveTitleFromPosts < GroongaClientModel::Migration
|
24
|
+
def change
|
25
|
+
remove_column :posts, :title
|
26
|
+
end
|
27
|
+
end
|
28
|
+
MIGRATION
|
29
|
+
end
|
30
|
+
|
31
|
+
test "create_table" do
|
32
|
+
run_generator(["create_posts"])
|
33
|
+
assert_migration("db/groonga/migrate/create_posts.rb", <<-MIGRATION)
|
34
|
+
class CreatePosts < GroongaClientModel::Migration
|
35
|
+
def change
|
36
|
+
create_table :posts do |t|
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
MIGRATION
|
41
|
+
end
|
42
|
+
|
43
|
+
test "create_table: _key" do
|
44
|
+
run_generator(["create_posts", "_key:short_text"])
|
45
|
+
assert_migration("db/groonga/migrate/create_posts.rb", <<-MIGRATION)
|
46
|
+
class CreatePosts < GroongaClientModel::Migration
|
47
|
+
def change
|
48
|
+
create_table :posts,
|
49
|
+
type: :hash_table,
|
50
|
+
key_type: :short_text do |t|
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
MIGRATION
|
55
|
+
end
|
56
|
+
|
57
|
+
test "set_config" do
|
58
|
+
run_generator(["set_config_alias_column"])
|
59
|
+
assert_migration("db/groonga/migrate/set_config_alias_column.rb", <<-MIGRATION)
|
60
|
+
class SetConfigAliasColumn < GroongaClientModel::Migration
|
61
|
+
def up
|
62
|
+
set_config "alias.column", "new value"
|
63
|
+
end
|
64
|
+
|
65
|
+
def down
|
66
|
+
# set_config "alias.column", "old value"
|
67
|
+
# delete_config "alias.column"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
MIGRATION
|
71
|
+
end
|
72
|
+
|
73
|
+
test "set_config: value" do
|
74
|
+
run_generator(["set_config_alias_column", "aliases.real_name"])
|
75
|
+
assert_migration("db/groonga/migrate/set_config_alias_column.rb", <<-MIGRATION)
|
76
|
+
class SetConfigAliasColumn < GroongaClientModel::Migration
|
77
|
+
def up
|
78
|
+
set_config "alias.column", "aliases.real_name"
|
79
|
+
end
|
80
|
+
|
81
|
+
def down
|
82
|
+
# set_config "alias.column", "old value"
|
83
|
+
# delete_config "alias.column"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
MIGRATION
|
87
|
+
end
|
88
|
+
|
89
|
+
test "delete_config" do
|
90
|
+
run_generator(["delete_config_alias_column"])
|
91
|
+
assert_migration("db/groonga/migrate/delete_config_alias_column.rb", <<-MIGRATION)
|
92
|
+
class DeleteConfigAliasColumn < GroongaClientModel::Migration
|
93
|
+
def up
|
94
|
+
delete_config "alias.column"
|
95
|
+
end
|
96
|
+
|
97
|
+
def down
|
98
|
+
# set_config "alias.column", "old value"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
MIGRATION
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
"%M��(Y���f�bgN��!�+�ZR?�Q�IE�
|
@@ -0,0 +1 @@
|
|
1
|
+
"%�o1��?P�k�0�pw�Ře���^�r��e���
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# Copyright (C) 2017 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
class TestMigrationConfig < Test::Unit::TestCase
|
18
|
+
include GroongaClientModel::TestHelper
|
19
|
+
include TestHelper::Migration
|
20
|
+
|
21
|
+
test("#set_config") do
|
22
|
+
expected_up_report = <<-REPORT
|
23
|
+
-- set_config("alias.column", "aliases.real_name")
|
24
|
+
-> 0.0s
|
25
|
+
REPORT
|
26
|
+
expected_down_report = nil
|
27
|
+
expected_dump = <<-DUMP.chomp
|
28
|
+
config_set alias.column aliases.real_name
|
29
|
+
DUMP
|
30
|
+
assert_migrate(expected_up_report,
|
31
|
+
expected_down_report,
|
32
|
+
expected_dump) do |migration|
|
33
|
+
migration.instance_eval do
|
34
|
+
set_config("alias.column", "aliases.real_name")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
test("#delete_config") do
|
40
|
+
open_client do |client|
|
41
|
+
client.request(:config_set).
|
42
|
+
parameter(:key, "alias.column").
|
43
|
+
parameter(:value, "aliases.real_name").
|
44
|
+
response
|
45
|
+
end
|
46
|
+
|
47
|
+
expected_up_report = <<-REPORT
|
48
|
+
-- delete_config("alias.column")
|
49
|
+
-> 0.0s
|
50
|
+
REPORT
|
51
|
+
expected_down_report = nil
|
52
|
+
expected_dump = <<-DUMP.chomp
|
53
|
+
DUMP
|
54
|
+
assert_migrate(expected_up_report,
|
55
|
+
expected_down_report,
|
56
|
+
expected_dump) do |migration|
|
57
|
+
migration.instance_eval do
|
58
|
+
delete_config("alias.column")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# Copyright (C) 2017 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
class TestMigrationCopy < Test::Unit::TestCase
|
18
|
+
include GroongaClientModel::TestHelper
|
19
|
+
include TestHelper::Migration
|
20
|
+
|
21
|
+
setup do
|
22
|
+
open_client do |client|
|
23
|
+
client.table_create(name: "posts",
|
24
|
+
flags: "TABLE_HASH_KEY",
|
25
|
+
key_type: "ShortText")
|
26
|
+
client.column_create(table: "posts",
|
27
|
+
name: "content",
|
28
|
+
flags: "COLUMN_SCALAR",
|
29
|
+
type: "Text")
|
30
|
+
client.table_create(name: "entries",
|
31
|
+
flags: "TABLE_PAT_KEY",
|
32
|
+
key_type: "ShortText")
|
33
|
+
client.column_create(table: "entries",
|
34
|
+
name: "content",
|
35
|
+
flags: "COLUMN_SCALAR",
|
36
|
+
type: "LongText")
|
37
|
+
values = [
|
38
|
+
{"_key" => "Groonga", "content" => "Very good!"},
|
39
|
+
{"_key" => "Ruby", "content" => "Very exciting!"},
|
40
|
+
]
|
41
|
+
client.load(table: "posts",
|
42
|
+
values: values)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
test("#copy_table") do
|
47
|
+
expected_up_report = <<-REPORT
|
48
|
+
-- copy_table(:posts, :entries)
|
49
|
+
-> 0.0s
|
50
|
+
REPORT
|
51
|
+
expected_down_report = nil
|
52
|
+
expected_dump = <<-DUMP.chomp
|
53
|
+
table_create entries TABLE_PAT_KEY ShortText
|
54
|
+
column_create entries content COLUMN_SCALAR LongText
|
55
|
+
|
56
|
+
table_create posts TABLE_HASH_KEY ShortText
|
57
|
+
column_create posts content COLUMN_SCALAR Text
|
58
|
+
|
59
|
+
load --table entries
|
60
|
+
[
|
61
|
+
["_key","content"],
|
62
|
+
["Groonga",""],
|
63
|
+
["Ruby",""]
|
64
|
+
]
|
65
|
+
|
66
|
+
load --table posts
|
67
|
+
[
|
68
|
+
["_key","content"],
|
69
|
+
["Groonga","Very good!"],
|
70
|
+
["Ruby","Very exciting!"]
|
71
|
+
]
|
72
|
+
DUMP
|
73
|
+
assert_migrate(expected_up_report,
|
74
|
+
expected_down_report,
|
75
|
+
expected_dump) do |migration|
|
76
|
+
migration.instance_eval do
|
77
|
+
copy_table(:posts, :entries)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
test("#copy_column") do
|
83
|
+
expected_up_report = <<-REPORT
|
84
|
+
-- copy_column("posts.content", "entries.content")
|
85
|
+
-> 0.0s
|
86
|
+
REPORT
|
87
|
+
expected_down_report = nil
|
88
|
+
expected_dump = <<-DUMP.chomp
|
89
|
+
table_create entries TABLE_PAT_KEY ShortText
|
90
|
+
column_create entries content COLUMN_SCALAR LongText
|
91
|
+
|
92
|
+
table_create posts TABLE_HASH_KEY ShortText
|
93
|
+
column_create posts content COLUMN_SCALAR Text
|
94
|
+
|
95
|
+
load --table entries
|
96
|
+
[
|
97
|
+
["_key","content"],
|
98
|
+
["Groonga","Very good!"],
|
99
|
+
["Ruby","Very exciting!"]
|
100
|
+
]
|
101
|
+
|
102
|
+
load --table posts
|
103
|
+
[
|
104
|
+
["_key","content"],
|
105
|
+
["Groonga","Very good!"],
|
106
|
+
["Ruby","Very exciting!"]
|
107
|
+
]
|
108
|
+
DUMP
|
109
|
+
assert_migrate(expected_up_report,
|
110
|
+
expected_down_report,
|
111
|
+
expected_dump) do |migration|
|
112
|
+
migration.instance_eval do
|
113
|
+
copy_column("posts.content", "entries.content")
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,528 @@
|
|
1
|
+
# Copyright (C) 2017 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
class TestMigrationCreateTable < Test::Unit::TestCase
|
18
|
+
include GroongaClientModel::TestHelper
|
19
|
+
include TestHelper::Migration
|
20
|
+
|
21
|
+
test("default") do
|
22
|
+
expected_up_report = <<-REPORT
|
23
|
+
-- create_table(:posts, {:type=>"TABLE_NO_KEY"})
|
24
|
+
-> 0.0s
|
25
|
+
REPORT
|
26
|
+
expected_down_report = <<-REPORT
|
27
|
+
-- remove_table(:posts)
|
28
|
+
-> 0.0s
|
29
|
+
REPORT
|
30
|
+
expected_dump = <<-DUMP.chomp
|
31
|
+
table_create posts TABLE_NO_KEY
|
32
|
+
DUMP
|
33
|
+
assert_migrate(expected_up_report,
|
34
|
+
expected_down_report,
|
35
|
+
expected_dump) do |migration|
|
36
|
+
migration.instance_eval do
|
37
|
+
create_table(:posts)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
sub_test_case(":type => :patricia_trie") do
|
43
|
+
test("default") do
|
44
|
+
expected_up_report = <<-REPORT
|
45
|
+
-- create_table(:terms, {:type=>"TABLE_PAT_KEY", :key_type=>"ShortText"})
|
46
|
+
-> 0.0s
|
47
|
+
REPORT
|
48
|
+
expected_down_report = <<-REPORT
|
49
|
+
-- remove_table(:terms)
|
50
|
+
-> 0.0s
|
51
|
+
REPORT
|
52
|
+
expected_dump = <<-DUMP.chomp
|
53
|
+
table_create terms TABLE_PAT_KEY ShortText
|
54
|
+
DUMP
|
55
|
+
assert_migrate(expected_up_report,
|
56
|
+
expected_down_report,
|
57
|
+
expected_dump) do |migration|
|
58
|
+
migration.instance_eval do
|
59
|
+
create_table(:terms, :type => :patricia_trie)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
test("tokenizer") do
|
65
|
+
expected_up_report = <<-REPORT
|
66
|
+
-- create_table(:terms, {:type=>"TABLE_PAT_KEY", :key_type=>"ShortText", :tokenizer=>"TokenBigram"})
|
67
|
+
-> 0.0s
|
68
|
+
REPORT
|
69
|
+
expected_down_report = <<-REPORT
|
70
|
+
-- remove_table(:terms)
|
71
|
+
-> 0.0s
|
72
|
+
REPORT
|
73
|
+
expected_dump = <<-DUMP.chomp
|
74
|
+
table_create terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram
|
75
|
+
DUMP
|
76
|
+
assert_migrate(expected_up_report,
|
77
|
+
expected_down_report,
|
78
|
+
expected_dump) do |migration|
|
79
|
+
migration.instance_eval do
|
80
|
+
create_table(:terms,
|
81
|
+
:type => :patricia_trie,
|
82
|
+
:tokenizer => :bigram)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
test("normalizer") do
|
88
|
+
expected_up_report = <<-REPORT
|
89
|
+
-- create_table(:terms, {:type=>"TABLE_PAT_KEY", :key_type=>"ShortText", :normalizer=>"NormalizerAuto"})
|
90
|
+
-> 0.0s
|
91
|
+
REPORT
|
92
|
+
expected_down_report = <<-REPORT
|
93
|
+
-- remove_table(:terms)
|
94
|
+
-> 0.0s
|
95
|
+
REPORT
|
96
|
+
expected_dump = <<-DUMP.chomp
|
97
|
+
table_create terms TABLE_PAT_KEY ShortText --normalizer NormalizerAuto
|
98
|
+
DUMP
|
99
|
+
assert_migrate(expected_up_report,
|
100
|
+
expected_down_report,
|
101
|
+
expected_dump) do |migration|
|
102
|
+
migration.instance_eval do
|
103
|
+
create_table(:terms,
|
104
|
+
:type => :patricia_trie,
|
105
|
+
:normalizer => :auto)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
sub_test_case("propose") do
|
112
|
+
test("full_text_search") do
|
113
|
+
expected_up_report = <<-REPORT
|
114
|
+
-- create_table(:terms, {:type=>"TABLE_PAT_KEY", :key_type=>"ShortText", :tokenizer=>"TokenBigram", :normalizer=>"NormalizerAuto"})
|
115
|
+
-> 0.0s
|
116
|
+
REPORT
|
117
|
+
expected_down_report = <<-REPORT
|
118
|
+
-- remove_table(:terms)
|
119
|
+
-> 0.0s
|
120
|
+
REPORT
|
121
|
+
expected_dump = <<-DUMP.chomp
|
122
|
+
table_create terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto
|
123
|
+
DUMP
|
124
|
+
assert_migrate(expected_up_report,
|
125
|
+
expected_down_report,
|
126
|
+
expected_dump) do |migration|
|
127
|
+
migration.instance_eval do
|
128
|
+
create_table(:terms, :propose => :full_text_search)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
sub_test_case("columns") do
|
135
|
+
def assert_migrate_add_column(column_name,
|
136
|
+
groonga_type,
|
137
|
+
options={})
|
138
|
+
expected_up_report = <<-REPORT
|
139
|
+
-- create_table(:posts, {:type=>"TABLE_NO_KEY"})
|
140
|
+
-> 0.0s
|
141
|
+
-- add_column(:posts, :#{column_name}, {:flags=>["COLUMN_SCALAR"], :value_type=>#{groonga_type.inspect}})
|
142
|
+
-> 0.0s
|
143
|
+
REPORT
|
144
|
+
expected_down_report = <<-REPORT
|
145
|
+
-- remove_table(:posts)
|
146
|
+
-> 0.0s
|
147
|
+
REPORT
|
148
|
+
expected_dump = <<-DUMP.chomp
|
149
|
+
table_create posts TABLE_NO_KEY
|
150
|
+
column_create posts #{column_name} COLUMN_SCALAR #{groonga_type}
|
151
|
+
DUMP
|
152
|
+
assert_migrate(expected_up_report,
|
153
|
+
expected_down_report,
|
154
|
+
expected_dump) do |migration|
|
155
|
+
migration.instance_eval do
|
156
|
+
create_table(:posts) do |table|
|
157
|
+
yield(table)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
sub_test_case("#boolean") do
|
164
|
+
test("default") do
|
165
|
+
assert_migrate_add_column(:published, "Bool") do |table|
|
166
|
+
table.boolean(:published)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
test("alias: #bool") do
|
171
|
+
assert_migrate_add_column(:published, "Bool") do |table|
|
172
|
+
table.bool(:published)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
sub_test_case("#integer") do
|
178
|
+
test("default") do
|
179
|
+
assert_migrate_add_column(:score, "Int32") do |table|
|
180
|
+
table.integer(:score)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
test("bit: 8") do
|
185
|
+
assert_migrate_add_column(:score, "Int8") do |table|
|
186
|
+
table.integer(:score, bit: 8)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
test("bit: 16") do
|
191
|
+
assert_migrate_add_column(:score, "Int16") do |table|
|
192
|
+
table.integer(:score, bit: 16)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
test("bit: 32") do
|
197
|
+
assert_migrate_add_column(:score, "Int32") do |table|
|
198
|
+
table.integer(:score, bit: 32)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
test("bit: 64") do
|
203
|
+
assert_migrate_add_column(:score, "Int64") do |table|
|
204
|
+
table.integer(:score, bit: 64)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
test("bit: 8, unsigned: true") do
|
209
|
+
assert_migrate_add_column(:score, "UInt8") do |table|
|
210
|
+
table.integer(:score, bit: 8, unsigned: true)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
test("bit: 16, unsigned: true") do
|
215
|
+
assert_migrate_add_column(:score, "UInt16") do |table|
|
216
|
+
table.integer(:score, bit: 16, unsigned: true)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
test("bit: 32, unsigned: true") do
|
221
|
+
assert_migrate_add_column(:score, "UInt32") do |table|
|
222
|
+
table.integer(:score, bit: 32, unsigned: true)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
test("bit: 64, unsigned: true") do
|
227
|
+
assert_migrate_add_column(:score, "UInt64") do |table|
|
228
|
+
table.integer(:score, bit: 64, unsigned: true)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
sub_test_case("#float") do
|
234
|
+
test("default") do
|
235
|
+
assert_migrate_add_column(:score, "Float") do |table|
|
236
|
+
table.float(:score)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
sub_test_case("#time") do
|
242
|
+
test("default") do
|
243
|
+
assert_migrate_add_column(:published_at, "Time") do |table|
|
244
|
+
table.time(:published_at)
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
sub_test_case("#short_text") do
|
250
|
+
test("default") do
|
251
|
+
assert_migrate_add_column(:title, "ShortText") do |table|
|
252
|
+
table.short_text(:title)
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
sub_test_case("#text") do
|
258
|
+
test("default") do
|
259
|
+
assert_migrate_add_column(:content, "Text") do |table|
|
260
|
+
table.text(:content)
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
sub_test_case("#long_text") do
|
266
|
+
test("default") do
|
267
|
+
assert_migrate_add_column(:content, "LongText") do |table|
|
268
|
+
table.long_text(:content)
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
sub_test_case("#geo_point") do
|
274
|
+
test("default") do
|
275
|
+
assert_migrate_add_column(:location, "WGS84GeoPoint") do |table|
|
276
|
+
table.geo_point(:location)
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
test("datum: :wgs84") do
|
281
|
+
assert_migrate_add_column(:location, "WGS84GeoPoint") do |table|
|
282
|
+
table.geo_point(:location, datum: :wgs84)
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
test("datum: :tokyo") do
|
287
|
+
assert_migrate_add_column(:location, "TokyoGeoPoint") do |table|
|
288
|
+
table.geo_point(:location, datum: :tokyo)
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
test("alias: #wgs84_geo_point") do
|
293
|
+
assert_migrate_add_column(:location, "WGS84GeoPoint") do |table|
|
294
|
+
table.wgs84_geo_point(:location)
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
test("alias: #tokyo_geo_point") do
|
299
|
+
assert_migrate_add_column(:location, "TokyoGeoPoint") do |table|
|
300
|
+
table.tokyo_geo_point(:location)
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
sub_test_case("#reference") do
|
306
|
+
def assert_migrate_add_reference_column(column_name,
|
307
|
+
reference_table_name,
|
308
|
+
options={})
|
309
|
+
open_client do |client|
|
310
|
+
client.table_create(name: reference_table_name,
|
311
|
+
flags: "TABLE_HASH_KEY",
|
312
|
+
key_type: "ShortText")
|
313
|
+
end
|
314
|
+
|
315
|
+
flags = []
|
316
|
+
case options[:type]
|
317
|
+
when :vector
|
318
|
+
flags << "COLUMN_VECTOR"
|
319
|
+
else
|
320
|
+
flags << "COLUMN_SCALAR"
|
321
|
+
end
|
322
|
+
|
323
|
+
expected_up_report = <<-REPORT
|
324
|
+
-- create_table(:posts, {:type=>"TABLE_NO_KEY"})
|
325
|
+
-> 0.0s
|
326
|
+
-- add_column(:posts, :#{column_name}, {:flags=>#{flags.inspect}, :value_type=>#{reference_table_name.inspect}})
|
327
|
+
-> 0.0s
|
328
|
+
REPORT
|
329
|
+
expected_down_report = <<-REPORT
|
330
|
+
-- remove_table(:posts)
|
331
|
+
-> 0.0s
|
332
|
+
REPORT
|
333
|
+
expected_dump = <<-DUMP.chomp
|
334
|
+
table_create posts TABLE_NO_KEY
|
335
|
+
|
336
|
+
table_create #{reference_table_name} TABLE_HASH_KEY ShortText
|
337
|
+
|
338
|
+
column_create posts #{column_name} #{flags.join("|")} #{reference_table_name}
|
339
|
+
DUMP
|
340
|
+
assert_migrate(expected_up_report,
|
341
|
+
expected_down_report,
|
342
|
+
expected_dump) do |migration|
|
343
|
+
migration.instance_eval do
|
344
|
+
create_table(:posts) do |table|
|
345
|
+
yield(table)
|
346
|
+
end
|
347
|
+
end
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
test("default") do
|
352
|
+
assert_migrate_add_reference_column(:user, :users) do |table|
|
353
|
+
table.reference(:user, :users)
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
test("type: :vector") do
|
358
|
+
assert_migrate_add_reference_column(:user,
|
359
|
+
:users,
|
360
|
+
type: :vector) do |table|
|
361
|
+
table.reference(:user, :users, type: :vector)
|
362
|
+
end
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
sub_test_case("#timestamps") do
|
367
|
+
test("default") do
|
368
|
+
expected_up_report = <<-REPORT
|
369
|
+
-- create_table(:posts, {:type=>"TABLE_NO_KEY"})
|
370
|
+
-> 0.0s
|
371
|
+
-- add_column(:posts, :created_at, {:flags=>["COLUMN_SCALAR"], :value_type=>"Time"})
|
372
|
+
-> 0.0s
|
373
|
+
-- add_column(:posts, :updated_at, {:flags=>["COLUMN_SCALAR"], :value_type=>"Time"})
|
374
|
+
-> 0.0s
|
375
|
+
REPORT
|
376
|
+
expected_down_report = <<-REPORT
|
377
|
+
-- remove_table(:posts)
|
378
|
+
-> 0.0s
|
379
|
+
REPORT
|
380
|
+
expected_dump = <<-DUMP.chomp
|
381
|
+
table_create posts TABLE_NO_KEY
|
382
|
+
column_create posts created_at COLUMN_SCALAR Time
|
383
|
+
column_create posts updated_at COLUMN_SCALAR Time
|
384
|
+
DUMP
|
385
|
+
assert_migrate(expected_up_report,
|
386
|
+
expected_down_report,
|
387
|
+
expected_dump) do |migration|
|
388
|
+
migration.instance_eval do
|
389
|
+
create_table(:posts) do |table|
|
390
|
+
table.timestamps
|
391
|
+
end
|
392
|
+
end
|
393
|
+
end
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
sub_test_case("#index") do
|
398
|
+
test("for full text search") do
|
399
|
+
expected_up_report = <<-REPORT
|
400
|
+
-- create_table(:posts, {:type=>"TABLE_NO_KEY"})
|
401
|
+
-> 0.0s
|
402
|
+
-- add_column(:posts, :content, {:flags=>["COLUMN_SCALAR"], :value_type=>"Text"})
|
403
|
+
-> 0.0s
|
404
|
+
-- create_table(:terms, {:type=>"TABLE_PAT_KEY", :key_type=>"ShortText", :tokenizer=>"TokenBigram", :normalizer=>"NormalizerAuto"})
|
405
|
+
-> 0.0s
|
406
|
+
-- add_column(:terms, "posts_content", {:flags=>["COLUMN_INDEX", "WITH_POSITION"], :value_type=>:posts, :sources=>[:content]})
|
407
|
+
-> 0.0s
|
408
|
+
REPORT
|
409
|
+
expected_down_report = <<-REPORT
|
410
|
+
-- remove_table(:terms)
|
411
|
+
-> 0.0s
|
412
|
+
-- remove_table(:posts)
|
413
|
+
-> 0.0s
|
414
|
+
REPORT
|
415
|
+
expected_dump = <<-DUMP.chomp
|
416
|
+
table_create posts TABLE_NO_KEY
|
417
|
+
column_create posts content COLUMN_SCALAR Text
|
418
|
+
|
419
|
+
table_create terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto
|
420
|
+
|
421
|
+
column_create terms posts_content COLUMN_INDEX|WITH_POSITION posts content
|
422
|
+
DUMP
|
423
|
+
assert_migrate(expected_up_report,
|
424
|
+
expected_down_report,
|
425
|
+
expected_dump) do |migration|
|
426
|
+
migration.instance_eval do
|
427
|
+
create_table(:posts) do |table|
|
428
|
+
table.text(:content)
|
429
|
+
end
|
430
|
+
|
431
|
+
create_table(:terms,
|
432
|
+
:type => :patricia_trie,
|
433
|
+
:tokenizer => :bigram,
|
434
|
+
:normalizer => :auto) do |table|
|
435
|
+
table.index(:posts, :content)
|
436
|
+
end
|
437
|
+
end
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
test("multi sources") do
|
442
|
+
expected_up_report = <<-REPORT
|
443
|
+
-- create_table(:posts, {:type=>"TABLE_NO_KEY"})
|
444
|
+
-> 0.0s
|
445
|
+
-- add_column(:posts, :title, {:flags=>["COLUMN_SCALAR"], :value_type=>"ShortText"})
|
446
|
+
-> 0.0s
|
447
|
+
-- add_column(:posts, :content, {:flags=>["COLUMN_SCALAR"], :value_type=>"Text"})
|
448
|
+
-> 0.0s
|
449
|
+
-- create_table(:terms, {:type=>"TABLE_PAT_KEY", :key_type=>"ShortText", :tokenizer=>"TokenBigram", :normalizer=>"NormalizerAuto"})
|
450
|
+
-> 0.0s
|
451
|
+
-- add_column(:terms, "posts_title_content", {:flags=>["COLUMN_INDEX", "WITH_POSITION", "WITH_SECTION"], :value_type=>:posts, :sources=>[:title, :content]})
|
452
|
+
-> 0.0s
|
453
|
+
REPORT
|
454
|
+
expected_down_report = <<-REPORT
|
455
|
+
-- remove_table(:terms)
|
456
|
+
-> 0.0s
|
457
|
+
-- remove_table(:posts)
|
458
|
+
-> 0.0s
|
459
|
+
REPORT
|
460
|
+
expected_dump = <<-DUMP.chomp
|
461
|
+
table_create posts TABLE_NO_KEY
|
462
|
+
column_create posts content COLUMN_SCALAR Text
|
463
|
+
column_create posts title COLUMN_SCALAR ShortText
|
464
|
+
|
465
|
+
table_create terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto
|
466
|
+
|
467
|
+
column_create terms posts_title_content COLUMN_INDEX|WITH_SECTION|WITH_POSITION posts title,content
|
468
|
+
DUMP
|
469
|
+
assert_migrate(expected_up_report,
|
470
|
+
expected_down_report,
|
471
|
+
expected_dump) do |migration|
|
472
|
+
migration.instance_eval do
|
473
|
+
create_table(:posts) do |table|
|
474
|
+
table.short_text(:title)
|
475
|
+
table.text(:content)
|
476
|
+
end
|
477
|
+
|
478
|
+
create_table(:terms,
|
479
|
+
:propose => :full_text_search) do |table|
|
480
|
+
table.index(:posts, [:title, :content])
|
481
|
+
end
|
482
|
+
end
|
483
|
+
end
|
484
|
+
end
|
485
|
+
|
486
|
+
test("custom name") do
|
487
|
+
expected_up_report = <<-REPORT
|
488
|
+
-- create_table(:posts, {:type=>"TABLE_NO_KEY"})
|
489
|
+
-> 0.0s
|
490
|
+
-- add_column(:posts, :content, {:flags=>["COLUMN_SCALAR"], :value_type=>"Text"})
|
491
|
+
-> 0.0s
|
492
|
+
-- create_table(:terms, {:type=>"TABLE_PAT_KEY", :key_type=>"ShortText", :tokenizer=>"TokenBigram", :normalizer=>"NormalizerAuto"})
|
493
|
+
-> 0.0s
|
494
|
+
-- add_column(:terms, :posts, {:flags=>["COLUMN_INDEX", "WITH_POSITION"], :value_type=>:posts, :sources=>[:content]})
|
495
|
+
-> 0.0s
|
496
|
+
REPORT
|
497
|
+
expected_down_report = <<-REPORT
|
498
|
+
-- remove_table(:terms)
|
499
|
+
-> 0.0s
|
500
|
+
-- remove_table(:posts)
|
501
|
+
-> 0.0s
|
502
|
+
REPORT
|
503
|
+
expected_dump = <<-DUMP.chomp
|
504
|
+
table_create posts TABLE_NO_KEY
|
505
|
+
column_create posts content COLUMN_SCALAR Text
|
506
|
+
|
507
|
+
table_create terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto
|
508
|
+
|
509
|
+
column_create terms posts COLUMN_INDEX|WITH_POSITION posts content
|
510
|
+
DUMP
|
511
|
+
assert_migrate(expected_up_report,
|
512
|
+
expected_down_report,
|
513
|
+
expected_dump) do |migration|
|
514
|
+
migration.instance_eval do
|
515
|
+
create_table(:posts) do |table|
|
516
|
+
table.text(:content)
|
517
|
+
end
|
518
|
+
|
519
|
+
create_table(:terms,
|
520
|
+
:propose => :full_text_search) do |table|
|
521
|
+
table.index(:posts, [:content], name: :posts)
|
522
|
+
end
|
523
|
+
end
|
524
|
+
end
|
525
|
+
end
|
526
|
+
end
|
527
|
+
end
|
528
|
+
end
|