Skip to content

Commit 63bb229

Browse files
committed
insert lucene version in new design documents if missing
1 parent a59f5e0 commit 63bb229

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/nouveau/include/nouveau.hrl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
%% limitations under the License.
1313

1414
-define(LEGACY_LUCENE_VERSION, 9).
15+
-define(TARGET_LUCENE_VERSION, 10).
1516

1617
-record(index, {
1718
dbname,

src/nouveau/src/nouveau_plugin_couch_db.erl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,46 @@
1313
-module(nouveau_plugin_couch_db).
1414

1515
-export([
16+
before_doc_update/3,
1617
is_valid_purge_client/2,
1718
on_compact/2
1819
]).
1920

21+
-include("nouveau.hrl").
22+
-include_lib("couch/include/couch_db.hrl").
23+
24+
%% New index definitions get an explicit lucene version property, if missing.
25+
before_doc_update(
26+
#doc{id = <<?DESIGN_DOC_PREFIX, _/binary>>, revs = {0, []}} = Doc,
27+
Db,
28+
?INTERACTIVE_EDIT = UpdateType
29+
) ->
30+
#doc{body = {Fields}} = Doc,
31+
case couch_util:get_value(<<"nouveau">>, Fields) of
32+
{Indexes} when is_list(Indexes) ->
33+
[add_versions_to_doc(Doc), Db, UpdateType];
34+
_ ->
35+
[Doc, Db, UpdateType]
36+
end;
37+
before_doc_update(Doc, Db, UpdateType) ->
38+
[Doc, Db, UpdateType].
39+
40+
add_versions_to_doc(#doc{} = Doc) ->
41+
#doc{body = {Fields0}} = Doc,
42+
{Indexes0} = couch_util:get_value(<<"nouveau">>, Fields0),
43+
Indexes1 = lists:map(fun add_version_to_index/1, Indexes0),
44+
Fields1 = couch_util:set_value(<<"nouveau">>, Fields0, {Indexes1}),
45+
Doc#doc{body = {Fields1}}.
46+
47+
add_version_to_index({IndexName, {Index}}) ->
48+
case couch_util:get_value(<<"lucene_version">>, Index) of
49+
undefined ->
50+
{IndexName,
51+
{couch_util:set_value(<<"lucene_version">>, Index, ?TARGET_LUCENE_VERSION)}};
52+
_ ->
53+
{IndexName, {Index}}
54+
end.
55+
2056
is_valid_purge_client(DbName, Props) ->
2157
nouveau_util:verify_index_exists(DbName, Props).
2258

0 commit comments

Comments
 (0)