diff --git a/src/Monocle/Backend/Index.hs b/src/Monocle/Backend/Index.hs index 478538f9d..726648571 100644 --- a/src/Monocle/Backend/Index.hs +++ b/src/Monocle/Backend/Index.hs @@ -55,6 +55,7 @@ instance ToJSON AuthorMapping where object [ "uid" .= object ["type" .= ("keyword" :: Text)] , "muid" .= object ["type" .= ("keyword" :: Text)] + , "groups" .= object ["type" .= ("keyword" :: Text)] ] instance ToJSON AuthorIndexMapping where @@ -121,109 +122,111 @@ data BoolMapping = BoolMapping deriving (Eq, Show) instance ToJSON BoolMapping where toJSON BoolMapping = object ["type" .= ("boolean" :: Text)] +schema :: [Pair] +schema = + [ "properties" + .= object + ( [ "id" .= KWMapping + , "type" .= KWMapping + , "number" .= KWMapping + , "change_id" .= KWMapping + , "title" .= TextAndKWMapping + , "text" .= TextAndKWMapping + , "url" .= KWMapping + , "commit_count" .= IntegerMapping + , "additions" .= IntegerMapping + , "deletions" .= IntegerMapping + , "change_files_count" .= IntegerMapping + , "changed_files" + .= object + [ "properties" + .= object + [ "additions" .= IntegerMapping + , "deletions" .= IntegerMapping + , "path" .= KWMapping + ] + ] + , "commits" + .= object + [ "properties" + .= object + [ "sha" .= KWMapping + , "author" .= AuthorIndexMapping + , "committer" .= AuthorIndexMapping + , "authored_at" .= DateIndexMapping + , "committed_at" .= DateIndexMapping + , "additions" .= IntegerMapping + , "deletions" .= IntegerMapping + , "title" .= object ["type" .= ("text" :: Text)] + ] + ] + , "repository_prefix" .= KWMapping + , "repository_fullname" .= KWMapping + , "repository_shortname" .= KWMapping + , "author" .= AuthorIndexMapping + , "on_author" .= AuthorIndexMapping + , "committer" .= AuthorIndexMapping + , "merged_by" .= AuthorIndexMapping + , "branch" .= KWMapping + , "target_branch" .= KWMapping + , "created_at" .= DateIndexMapping + , "on_created_at" .= DateIndexMapping + , "merged_at" .= DateIndexMapping + , "updated_at" .= DateIndexMapping + , "closed_at" .= DateIndexMapping + , "state" .= KWMapping + , "duration" .= IntegerMapping + , "mergeable" .= KWMapping + , "labels" .= KWMapping + , "assignees" + .= object + [ "type" .= ("nested" :: Text) + , "properties" .= AuthorMapping + ] + , "approval" .= KWMapping + , "draft" .= BoolMapping + , "self_merged" .= BoolMapping + , "crawler_metadata" + .= object + [ "properties" + .= object + [ "crawler_name" .= KWMapping + , "crawler_type" .= KWMapping + , "crawler_type_value" .= KWMapping + , "last_commit_at" .= DateIndexMapping + , "last_post_at" .= DateIndexMapping + , "total_docs_posted" .= IntegerMapping + , "total_changes_updated" .= IntegerMapping + , "total_change_events_updated" .= IntegerMapping + , "total_orphans_updated" .= IntegerMapping + ] + ] + , "tasks_data" + .= object + [ "properties" + .= object + [ "tid" .= KWMapping + , "ttype" .= KWMapping + , "crawler_name" .= KWMapping + , "updated_at" .= DateIndexMapping + , "change_url" .= KWMapping + , "severity" .= KWMapping + , "priority" .= KWMapping + , "score" .= IntegerMapping + , "url" .= KWMapping + , "prefix" .= KWMapping + , "title" .= TextAndKWMapping + , "_adopted" .= BoolMapping + ] + ] + ] + <> cachedAuthorField + <> mergedCommitField + ) + ] + instance ToJSON ChangesIndexMapping where - toJSON ChangesIndexMapping = - object - [ "properties" - .= object - ( [ "id" .= KWMapping - , "type" .= KWMapping - , "number" .= KWMapping - , "change_id" .= KWMapping - , "title" .= TextAndKWMapping - , "text" .= TextAndKWMapping - , "url" .= KWMapping - , "commit_count" .= IntegerMapping - , "additions" .= IntegerMapping - , "deletions" .= IntegerMapping - , "change_files_count" .= IntegerMapping - , "changed_files" - .= object - [ "properties" - .= object - [ "additions" .= IntegerMapping - , "deletions" .= IntegerMapping - , "path" .= KWMapping - ] - ] - , "commits" - .= object - [ "properties" - .= object - [ "sha" .= KWMapping - , "author" .= AuthorIndexMapping - , "committer" .= AuthorIndexMapping - , "authored_at" .= DateIndexMapping - , "committed_at" .= DateIndexMapping - , "additions" .= IntegerMapping - , "deletions" .= IntegerMapping - , "title" .= object ["type" .= ("text" :: Text)] - ] - ] - , "repository_prefix" .= KWMapping - , "repository_fullname" .= KWMapping - , "repository_shortname" .= KWMapping - , "author" .= AuthorIndexMapping - , "on_author" .= AuthorIndexMapping - , "committer" .= AuthorIndexMapping - , "merged_by" .= AuthorIndexMapping - , "branch" .= KWMapping - , "target_branch" .= KWMapping - , "created_at" .= DateIndexMapping - , "on_created_at" .= DateIndexMapping - , "merged_at" .= DateIndexMapping - , "updated_at" .= DateIndexMapping - , "closed_at" .= DateIndexMapping - , "state" .= KWMapping - , "duration" .= IntegerMapping - , "mergeable" .= KWMapping - , "labels" .= KWMapping - , "assignees" - .= object - [ "type" .= ("nested" :: Text) - , "properties" .= AuthorMapping - ] - , "approval" .= KWMapping - , "draft" .= BoolMapping - , "self_merged" .= BoolMapping - , "crawler_metadata" - .= object - [ "properties" - .= object - [ "crawler_name" .= KWMapping - , "crawler_type" .= KWMapping - , "crawler_type_value" .= KWMapping - , "last_commit_at" .= DateIndexMapping - , "last_post_at" .= DateIndexMapping - , "total_docs_posted" .= IntegerMapping - , "total_changes_updated" .= IntegerMapping - , "total_change_events_updated" .= IntegerMapping - , "total_orphans_updated" .= IntegerMapping - ] - ] - , "tasks_data" - .= object - [ "properties" - .= object - [ "tid" .= KWMapping - , "ttype" .= KWMapping - , "crawler_name" .= KWMapping - , "updated_at" .= DateIndexMapping - , "change_url" .= KWMapping - , "severity" .= KWMapping - , "priority" .= KWMapping - , "score" .= IntegerMapping - , "url" .= KWMapping - , "prefix" .= KWMapping - , "title" .= TextAndKWMapping - , "_adopted" .= BoolMapping - ] - ] - ] - <> cachedAuthorField - <> mergedCommitField - ) - ] + toJSON ChangesIndexMapping = object schema createIndex :: (IndexEffects es, Retry :> es, ToJSON mapping) => BH.IndexName -> mapping -> Eff es () createIndex indexName mapping = do @@ -240,7 +243,7 @@ createIndex indexName mapping = do retryPolicy = exponentialBackoff 500_000 <> limitRetries 7 configVersion :: ConfigVersion -configVersion = ConfigVersion 5 +configVersion = ConfigVersion 6 configIndex :: BH.IndexName configIndex = BH.IndexName "monocle.config" @@ -373,6 +376,12 @@ upgradeConfigV5 = do logInfo "Applying migration to schema V5 on workspace" ["index" .= indexName] void $ esPutMapping indexName mergedCommitField +upgradeConfigV6 :: forall es. MonoQuery :> es => IndexEffects es => Eff es () +upgradeConfigV6 = do + indexName <- getIndexName + logInfo "Applying migration to schema V6 on workspace" ["index" .= indexName] + void $ esPutMapping indexName schema + upgrades :: forall es. (E.Fail :> es, MonoQuery :> es) => IndexEffects es => [(ConfigVersion, Eff es ())] upgrades = [ (ConfigVersion 1, upgradeConfigV1) @@ -380,6 +389,7 @@ upgrades = , (ConfigVersion 3, void upgradeConfigV3) , (ConfigVersion 4, void upgradeConfigV4) , (ConfigVersion 5, void upgradeConfigV5) + , (ConfigVersion 6, void upgradeConfigV6) ] newtype ConfigVersion = ConfigVersion Integer