URGENT - new issues after installing Changelog 0087

Hey Amit, everything went well with the UpdateIndexMapping command:

(cchq) ccc@monolith:~/commcare-cloud$ cchq monolith django-manage shell
[WARNING]: While constructing a mapping from <string>, line 105, column 3, found a duplicate dict key (ELASTICSEARCH_MAJOR_VERSION). Using last defined value only.
ssh ccc@10.3.0.4 -t -o UserKnownHostsFile=/home/ccc/environments/monolith/known_hosts 'sudo -iu cchq bash -c '"'"'cd /home/cchq/www/monolith/current; python_env/bin/python manage.py shell'"'"''
Ubuntu 22.04.5 LTS
Python 3.13.3 (main, Apr  9 2025, 04:03:52) [Clang 20.1.0 ]
Type 'copyright', 'credits' or 'license' for more information
IPython 9.3.0 -- An enhanced Interactive Python. Type '?' for help.
Tip: You can use Ctrl-O to force a new line in terminal IPython

In [1]: from corehq.apps.es.migration_operations import UpdateIndexMapping
   ...: from corehq.apps.es.transient_util import iter_doc_adapters
   ...:

In [2]: for adapter in iter_doc_adapters():
   ...:     print(adapter.index_name, adapter.type)
   ...:     UpdateIndexMapping(name=adapter.index_name, type_=adapter.type, properties=adapter.mapping['properties'], es_versions=[6]).run()
   ...:
apps-2024-05-09 app
2025-09-20 18:09:03,926 INFO [corehq.apps.es.migration_operations] Updating mappings for Elasticsearch index: apps-2024-05-09
--- before.py
+++ after.py
@@ -3,7 +3,7 @@
         "enabled": False
     },
     "_meta": {
-        "created": "2024-06-06T03:49:00.431884"
+        "created": "2025-09-20T18:09:03.926871"
     },
     "date_detection": False,
     "dynamic": "false",
cases-2024-05-09 case
2025-09-20 18:09:04,031 INFO [corehq.apps.es.migration_operations] Updating mappings for Elasticsearch index: cases-2024-05-09
--- before.py
+++ after.py
@@ -3,7 +3,7 @@
         "enabled": True
     },
     "_meta": {
-        "created": "2024-06-06T03:49:00.795386"
+        "created": "2025-09-20T18:09:04.031830"
     },
     "date_detection": False,
     "dynamic": "false",
case-search-2024-05-09 case
2025-09-20 18:09:04,087 INFO [corehq.apps.es.migration_operations] Updating mappings for Elasticsearch index: case-search-2024-05-09
--- before.py
+++ after.py
@@ -3,7 +3,7 @@
         "enabled": False
     },
     "_meta": {
-        "created": "2024-06-06T03:49:00.618525"
+        "created": "2025-09-20T18:09:04.087859"
     },
     "date_detection": False,
     "dynamic": "false",
domains-2024-05-09 hqdomain
2025-09-20 18:09:04,138 INFO [corehq.apps.es.migration_operations] Updating mappings for Elasticsearch index: domains-2024-05-09
--- before.py
+++ after.py
@@ -3,7 +3,7 @@
         "enabled": False
     },
     "_meta": {
-        "created": "2024-06-06T03:49:00.989325"
+        "created": "2025-09-20T18:09:04.138262"
     },
     "date_detection": False,
     "dynamic": "false",
forms-2024-05-09 xform
2025-09-20 18:09:04,206 INFO [corehq.apps.es.migration_operations] Updating mappings for Elasticsearch index: forms-2024-05-09
--- before.py
+++ after.py
@@ -3,7 +3,7 @@
         "enabled": True
     },
     "_meta": {
-        "created": "2024-06-06T03:49:01.177468"
+        "created": "2025-09-20T18:09:04.206554"
     },
     "date_detection": False,
     "dynamic": "false",
groups-2024-05-09 group
2025-09-20 18:09:04,259 INFO [corehq.apps.es.migration_operations] Updating mappings for Elasticsearch index: groups-2024-05-09
--- before.py
+++ after.py
@@ -3,7 +3,7 @@
         "enabled": True
     },
     "_meta": {
-        "created": "2024-06-06T03:49:01.372528"
+        "created": "2025-09-20T18:09:04.259255"
     },
     "date_detection": False,
     "dynamic": "false",
sms-2024-05-09 sms
2025-09-20 18:09:04,302 INFO [corehq.apps.es.migration_operations] Updating mappings for Elasticsearch index: sms-2024-05-09
--- before.py
+++ after.py
@@ -3,7 +3,7 @@
         "enabled": False
     },
     "_meta": {
-        "created": "2024-06-06T03:49:01.552646"
+        "created": "2025-09-20T18:09:04.301986"
     },
     "date_detection": False,
     "dynamic": "false",
users-2024-05-09 user
2025-09-20 18:09:04,357 INFO [corehq.apps.es.migration_operations] Updating mappings for Elasticsearch index: users-2024-05-09
--- before.py
+++ after.py
@@ -4,7 +4,7 @@
         "enabled": True
     },
     "_meta": {
-        "created": "2025-05-15T03:52:06.776539"
+        "created": "2025-09-20T18:09:04.357302"
     },
     "date_detection": False,
     "dynamic": "false",
@@ -454,6 +454,44 @@
                 }
             }
         },
+        "user_domain_memberships": {
+            "dynamic": "false",
+            "type": "nested",
+            "properties": {
+                "assigned_location_ids": {
+                    "type": "keyword"
+                },
+                "doc_type": {
+                    "type": "keyword"
+                },
+                "domain": {
+                    "fields": {
+                        "exact": {
+                            "type": "keyword"
+                        }
+                    },
+                    "type": "text"
+                },
+                "is_active": {
+                    "type": "boolean"
+                },
+                "is_admin": {
+                    "type": "boolean"
+                },
+                "location_id": {
+                    "type": "keyword"
+                },
+                "override_global_tz": {
+                    "type": "boolean"
+                },
+                "role_id": {
+                    "type": "keyword"
+                },
+                "timezone": {
+                    "type": "text"
+                }
+            }
+        },
         "user_location_id": {
             "type": "keyword"
         },

But when I run ./manage.py migrate it reports:

(commcare-hq) (monolith) cchq@monolith:~/www/monolith/current$ ./manage.py migrate
Operations to perform:
  Apply all migrations: accounting, admin, aggregate_ucrs, analytics, api, app_execution, app_manager, auditcare, auth, blobs, campaign, case_importer, case_search, cleanup, cloudcare, commtrack, consumption, contenttypes, couchforms, custom_data_fields, data_analytics, data_cleaning, data_dictionary, data_interfaces, dhis2, django_celery_results, django_digest, django_prbac, domain, domain_migration_flags, dropbox, email, enterprise, es, events, experiments, export, fhir, field_audit, fixtures, form_processor, formplayer_api, generic_inbound, geospatial, hqadmin, hqmedia, hqwebapp, integration, ip_access, ivr, linked_domain, locations, mobile_auth, motech, notifications, oauth2_provider, ota, otp_static, otp_totp, phone, phonelog, phonenumber, pillow_retry, pillowtop, preindex, products, project_limits, registration, registry, reminders, repeaters, reports, saved_reports, scheduling, scheduling_partitioned, sessions, sites, sms, smsbillables, smsforms, sql_accessors, sql_proxy_accessors, sql_proxy_standby_accessors, sso, start_enterprise, stock, tastypie, telerivet, toggle_ui, toggles, translations, user_importer, userreports, users, util, zapier
Running migrations:
  No migrations to apply.

Attempting to deploy Merge pull request #36980 from dimagi/create-pull-request/update-tran… · dimagi/commcare-hq@3a8f328 · GitHub results in another DB migration error, this time it seems related to CouchDB:

Claude.ai reports this after parsing the error:

The migration failed due to a missing CouchDB view in the users_by_domain design document. Here's what happened:

Root Cause: The migration script tried to access a CouchDB view at:

_design/users_by_domain/_view/view

But received a 404 error, indicating this view doesn't exist in the database.

At this stage I’m not sure if it’s safe to restore the snapshot prior to this attempted deployment or if I should go back to the snapshot prior to the ES 6 upgrade again.

We are moving forward, so the good thing is that all your ES issues are probably fixed.

But there is another issue which also probably is because of a migration not being applied properly on couch.

Can you try to run

./manage.py migrate preindex

This should create the missing view, and I believe you should be good to go.

At this stage I’m not sure if it’s safe to restore the snapshot prior to this attempted deployment or if I should go back to the snapshot prior to the ES 6 upgrade again.

I don’t think we are in a bad state right now. Things should work out from here.

1 Like

Hi Amit, thanks for the feedback, I receive this when running the above:

(commcare-hq) (monolith) cchq@monolith:~/www/monolith/current$ ./manage.py migrate preindex
Operations to perform:
  Apply all migrations: preindex
Running migrations:
  No migrations to apply.

I had restored the system just after the ES6 upgrade but before the attempted Merge pull request #36980 from dimagi/create-pull-request/update-tran… · dimagi/commcare-hq@3a8f328 · GitHub deployment.

Interesting! Looks like the migrations have been applied but the views have not created.

Can you try to running the command below to manually tell couch to sync all design docs?

./manage.py sync_prepare_couchdb_multi

1 Like

This was the result of the above command:

(commcare-hq) (monolith) cchq@monolith:~/www/monolith/current$ ./manage.py sync_prepare_couchdb_multi
2025-09-21 10:27:28,542 INFO [dimagi.utils.couch.sync_docs] synced 'builds' in couchdb
2025-09-21 10:27:28,547 INFO [dimagi.utils.couch.sync_docs] synced 'last_modified' in couchdb
2025-09-21 10:27:28,551 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:28,554 INFO [dimagi.utils.couch.sync_docs] synced 'export_instances_by_domain' in couchdb
2025-09-21 10:27:28,555 INFO [dimagi.utils.couch.sync_docs] synced 'users_extra' in couchdb
2025-09-21 10:27:28,557 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:28,559 INFO [dimagi.utils.couch.sync_docs] synced 'export_instances_by_is_daily_saved' in couchdb
2025-09-21 10:27:28,561 INFO [dimagi.utils.couch.sync_docs] synced 'forms_by_app_info' in couchdb
2025-09-21 10:27:28,564 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:28,566 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:28,577 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:28,583 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:28,641 INFO [dimagi.utils.couch.sync_docs] synced 'app_manager' in couchdb
2025-09-21 10:27:28,645 INFO [dimagi.utils.couch.sync_docs] synced 'apps_with_submissions' in couchdb
2025-09-21 10:27:28,678 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:28,682 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:28,798 INFO [dimagi.utils.couch.sync_docs] synced 'last_modified' in couchdb
2025-09-21 10:27:28,819 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:28,874 INFO [dimagi.utils.couch.sync_docs] synced 'program_by_code' in couchdb
2025-09-21 10:27:28,879 INFO [dimagi.utils.couch.sync_docs] synced 'last_modified' in couchdb
2025-09-21 10:27:28,885 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:28,888 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:28,895 INFO [dimagi.utils.couch.sync_docs] synced 'all_docs' in couchdb
2025-09-21 10:27:28,899 INFO [dimagi.utils.couch.sync_docs] synced 'all_docs' in couchdb
2025-09-21 10:27:28,903 INFO [dimagi.utils.couch.sync_docs] synced 'registry_data_sources_by_last_modified' in couchdb
2025-09-21 10:27:28,907 INFO [dimagi.utils.couch.sync_docs] synced 'all_docs' in couchdb
2025-09-21 10:27:28,909 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:28,912 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:28,920 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:28,923 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:28,930 INFO [dimagi.utils.couch.sync_docs] synced 'all_docs' in couchdb
2025-09-21 10:27:28,944 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:29,013 INFO [dimagi.utils.couch.sync_docs] synced 'all_docs' in couchdb
2025-09-21 10:27:29,133 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:29,213 INFO [dimagi.utils.couch.sync_docs] synced 'app_translations_by_popularity' in couchdb
2025-09-21 10:27:29,215 INFO [dimagi.utils.couch.sync_docs] synced 'tests' in couchdb
2025-09-21 10:27:29,219 INFO [dimagi.utils.couch.sync_docs] synced 'registry_data_sources' in couchdb
2025-09-21 10:27:29,224 INFO [dimagi.utils.couch.sync_docs] synced 'saved_apps_auto_generated' in couchdb
2025-09-21 10:27:29,226 INFO [dimagi.utils.couch.sync_docs] synced 'schemas_by_xmlns_or_case_type' in couchdb
2025-09-21 10:27:29,237 INFO [dimagi.utils.couch.sync_docs] synced 'registry_report_configs' in couchdb
2025-09-21 10:27:29,243 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:29,250 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:29,251 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:29,252 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:29,255 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:29,303 INFO [dimagi.utils.couch.sync_docs] synced 'reportconfig' in couchdb
2025-09-21 10:27:29,321 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:29,348 INFO [dimagi.utils.couch.sync_docs] synced 'by_domain_doc_type_date' in couchdb
2025-09-21 10:27:29,397 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:29,425 INFO [dimagi.utils.couch.sync_docs] synced 'by_domain_doc_type_date' in couchdb
2025-09-21 10:27:29,441 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:29,544 INFO [dimagi.utils.couch.sync_docs] synced 'by_domain_doc_type_date' in couchdb
2025-09-21 10:27:29,555 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:29,558 INFO [dimagi.utils.couch.sync_docs] synced 'by_domain_doc_type_date' in couchdb
2025-09-21 10:27:29,673 INFO [dimagi.utils.couch.sync_docs] synced 'exports_forms_by_app' in couchdb
2025-09-21 10:27:29,675 INFO [dimagi.utils.couch.sync_docs] synced 'deleted_users_by_username' in couchdb
2025-09-21 10:27:29,676 INFO [dimagi.utils.couch.sync_docs] synced 'by_domain_doc_type_date' in couchdb
2025-09-21 10:27:29,677 INFO [dimagi.utils.couch.sync_docs] synced 'doc_conflicts' in couchdb
2025-09-21 10:27:29,678 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:29,738 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:29,742 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:29,749 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:29,753 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:29,811 INFO [dimagi.utils.couch.sync_docs] synced 'hqadmin' in couchdb
All apps loaded into jobs, waiting...
2025-09-21 10:27:30,028 INFO [dimagi.utils.couch.sync_docs] synced 'domain' in couchdb
2025-09-21 10:27:30,031 INFO [dimagi.utils.couch.sync_docs] synced 'groups' in couchdb
2025-09-21 10:27:30,047 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:30,050 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:30,169 INFO [dimagi.utils.couch.sync_docs] synced 'mobile_auth' in couchdb
2025-09-21 10:27:30,184 INFO [dimagi.utils.couch.sync_docs] synced 'hqmedia' in couchdb
2025-09-21 10:27:30,186 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:30,194 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:30,222 INFO [dimagi.utils.couch.sync_docs] synced 'userreports' in couchdb
2025-09-21 10:27:30,228 INFO [dimagi.utils.couch.sync_docs] synced 'users' in couchdb
2025-09-21 10:27:30,233 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
2025-09-21 10:27:30,236 INFO [dimagi.utils.couch.sync_docs] Triggering view rebuild
All apps reported complete.
Preindex results:
	Initiated by: unknown
Total time: 2 seconds

Here is the result of the deploy –resume: another ES error on the migrations:

From claude.ai:

This is an Elasticsearch query syntax error during the migration. Here's the breakdown:

Root Cause: The migration 0083_reset_ccu_dm_is_active.py is trying to query Elasticsearch with a malformed nested query that Elasticsearch 6 cannot parse.

Specific Issue: The query is searching for CommCareUser documents with nested user_domain_memberships where is_active = false, but the nested query structure is invalid for the current Elasticsearch mapping.

Problem Areas:

  1. Nested field mapping mismatch - The field user_domain_memberships.is_active may not be properly mapped as a nested field

  2. Query syntax incompatibility - The query structure doesn't match what Elasticsearch 6 expects

  3. Index mapping issue - The user_domain_memberships path might not exist or be configured incorrectly

Failure Point:

  • Migration: 0083_reset_ccu_dm_is_active.py

  • Function: affected_ids() trying to scroll through Elasticsearch results

  • Query: Looking for inactive domain memberships

Next Steps:

  1. Check Elasticsearch mapping for the users index - verify user_domain_memberships is properly mapped as nested

  2. Validate the field exists - ensure user_domain_memberships.is_active field exists in the index

  3. Review query syntax - the nested query might need restructuring for ES6 compatibility

  4. Consider reindexing - the users index may need to be rebuilt with correct mappings

  5. Skip migration temporarily - if urgent, this specific migration could be marked as complete to proceed

Confirming that you have already applied suggestions in - URGENT - new issues after installing Changelog 0087 - #15 by aphulera ?

1 Like

Thanks Amit, I believe so but will double check when at my desk in 30 mins.

EDIT Amit, thank you - it was indeed that. I should have noticed that we had regressed after the initial success on the es migrations. I had restored an earlier snapshot this morning to restart these final updates but missed that one. The upgrade has completed and the server is running on ES6 at 3a8f328.

It’s a relief to have resolved this, thanks for the help.

1 Like

Glad to know it worked out.

Thanks again for your patience throughout the process, appreciate it :folded_hands:

1 Like