Migrate Aura Groot context (Dire Straits)

Guidelines for the migration of aura-groot database context schema from releases previous to Dire Straits to Dorian release onwards. Additionally, the rollback procedure is included.

Prerequisites

  • Mandatory requisite: A valid kubeconfig for the environment must be available.

  • Recommendation: Create a snapshot/backup of the current DB data.

Process for context DB migration

Access MongoDB console

To access and open MongoDB console we can use the kubectl command below to export the intended environment, with MongoDB adminuser password. Use the right environment and database name in the commands.

$ export ATLAS_DEPLOYMENT_NAME=aura-br-pro-70 # Get from kubectl get -n aura-system atlasdeployments.atlas.mongodb.com
$ export ATLAS_DATABASE_NAME=aura-groot-br-pro # Set with the correct DB of your deployment
$ export MONGODB_USER=$(kubectl get -n aura-system atlasdatabaseusers.atlas.mongodb.com mongodb-adminuser-password -o jsonpath='{.spec.username}')
$ export MONGODB_PASSWORD=$(kubectl get -n aura-system secret mongodb-adminuser-password -o go-template='{{ .data.password | base64decode }}')
$ export MONGODB_URI="$(kubectl get -n aura-system atlasdeployments.atlas.mongodb.com $ATLAS_DEPLOYMENT_NAME -o jsonpath='{.status.connectionStrings.standardSrv}'|sed "s|srv://|srv://$MONGODB_USER:$MONGODB_PASSWORD@|g")/${ATLAS_DATABASE_NAME}"
$ kubectl -n aura-system run fix-script -i -q --rm --restart=Never --image=mongo:latest --command mongosh ${MONGODB_URI}

Migrate context collection to new schema

  • Update documents to the new format:

    > db["aura-context"].aggregate([
          {
            $match: {
              _id: {
                $regex: "/conversations/",
              },
              "document.activeSkill.conversationId": {
                $exists: true,
              },
            },
          },
          {
            $lookup:
              {
                from: "aura-context",
                localField:
                  "document.activeSkill.conversationId",
                foreignField: "_id",
                as: "document.skillConversationReference",
              },
          },
          {
            $set: {
              "document.skillConversationReference": {
                $arrayElemAt: [
                  "$document.skillConversationReference",
                  0,
                ],
              },
            },
          },
          {
            $set: {
              "document.skillConversationReference":
                "$document.skillConversationReference.document",
            },
          },
          {
            $merge: "aura-context",
          },
        ])
    
  • Check if changes have been applied. The following query should return n documents:

      > db["aura-context"].find({"document.skillConversationReference": { $exists: true }})
    

Rollback to the previous schema

  • If a rollback is needed, documents should be modified to have the previous schema and maintain the users’ context data:

    > db["aura-context"].aggregate([
        {
          $match:
            {
              "document.activeSkill.conversationId": {
                $exists: true,
              },
              "document.skillConversationReference": {
                $exists: true,
              },
            },
        },
        {
          $project:
            {
              _id: "$document.activeSkill.conversationId",
              document:
                "$document.skillConversationReference",
              expiresAt: "$expiresAt",
            },
        },
        {
          $merge: "aura-context",
        },
      ])