Linked Application pointing to cloud upstream_app_id after full local server migration

Hello Team,

We have recently completed a full migration of our CommCare HQ environment from the Dimagi cloud to a self-hosted local server infrastructure. We are now in the final stages of our deployment, but we have encountered a structural linking issue with our linked applications.

Setup & Context:

  • Production Domain Space: mc-inscale (contains two linked applications: aplicativo do APS and aplicativo do supervisor). the client wants to maintain and continue to use all the versions that are part of the downstream applications

  • Development Domain Space: mc-inscale-dev (contains the active source applications: aplicativo do APS and aplicativo do supervisor). The development space was copied down to our new local server, which generated new application IDs on the local instance.

  • Client Requirements:

  1. The client needs to maintain and continue to use all historical versions that are already part of the downstream applications.

  2. Future updates should flow seamlessly from the newly established local development space (mc-inscale-dev) to the production space (mc-inscale).

The Issue:

We successfully established a project space link from mc-inscale-dev β†’ mc-inscale by name, and the Linked Project Spaces pages correctly show them linked to each other on our local server.

However, the individual linked applications are still pointing to the legacy Dimagi cloud upstream_app_id from before the migration rather than the new local app IDs generated when the dev space was copied down.

When inspecting via the Django shell (./manage.py shell), we verified the following:

from corehq.apps.app_manager.dbaccessors import get_app
app = get_app("mc-inscale", "c2161fa6d8bded80ecad5edd91582e32") # (aplicativo do APS linked)
print(app.doc_type, app.upstream_app_id, app.upstream_version)

Output:

LinkedApplication 240a8a42523112581841db1c0f15fd9e 5918

The upstream_app_id (240a8a42523112581841db1c0f15fd9e) still maps to the old cloud ID instead of the new local application ID residing in mc-inscale-dev.

Question:

What is the recommended method or management command to safely update or remap the upstream_app_id of an existing LinkedApplication to point to the new local development app ID without breaking sync functionality or release histories?

Any guidance or python snippet to handle this mapping update cleanly in the DB would be greatly appreciated.

Hi Demis,

You could try using the link_apps management command for each upstream/downstream pair, which should update the downstream apps to correctly reference the new upstream apps.

./manage.py link_apps <upstream_app_id> <downstream_app_id>

Prior to running this, make sure of the following:

  • a released build in the mc-inscale-dev project exists for each app that has been copied from the production server, as the command relies on this.
  • generally good practice to create a build of each downstream project prior to running this, just to have a clean point to revert to if needed.

Let us know how it goes.

1 Like

Hi Graham,

It worked! Thank you for the support. Everything is running smoothly now.