Skip to content

Write to the correct GitLab `identity` field for refreshTokens and add migration script to run after (migration phase 1)

Eric Eastwood requested to merge 2838-gitlab-identity-migration-pt1 into develop

Write to the correct GitLab identity field for refreshToken's and add migration script to run after (migration phase 1).

Part of #2838 (closed)

  1. First part of the migration (writing to the correct identity field, then migrating existing data)
  2. Second phase of the migration (actually using the refreshTokens), !2283 (merged)

Dev notes

node scripts/migration/fill-gitlab-identity-refresh-tokens.js

Working with Mongo indexes

$ mongo gitter
> db.identities.find({ provider: 'gitlab' })
> db.identities.getIndexes()
> db.identities.dropIndex("name")

How to check if the script is using the new index we added

To see if it's using the index, see how the relevant entry uses IXSCAN

Mongo commands
$ mongo gitter
> db.getProfilingLevel()
0
> db.setProfilingLevel(2)
{ "was" : 0, "slowms" : 100, "ok" : 1 }

# Run the migration script

> db.system.profile.find().pretty()
// ...
{
        "op" : "query",
        "ns" : "gitter.identities",
        "query" : {
                "find" : "identities",
                "filter" : {
                        "refreshToken" : {
                                "$exists" : false
                        },
                        "provider" : "gitlab"
                },
                "batchSize" : 500
        },
        "keysExamined" : 2,
        "docsExamined" : 2,
        "fromMultiPlanner" : true,
        "cursorExhausted" : true,
        "keyUpdates" : 0,
        "writeConflicts" : 0,
        "numYield" : 0,
        "locks" : {
                "Global" : {
                        "acquireCount" : {
                                "r" : NumberLong(2)
                        }
                },
                "Database" : {
                        "acquireCount" : {
                                "r" : NumberLong(1)
                        }
                },
                "Collection" : {
                        "acquireCount" : {
                                "r" : NumberLong(1)
                        }
                }
        },
        "nreturned" : 2,
        "responseLength" : 1020,
        "protocol" : "op_query",
        "millis" : 0,
        "execStats" : {
                "stage" : "FETCH",
                "filter" : {
                        "$not" : {
                                "refreshToken" : {
                                        "$exists" : true
                                }
                        }
                },
                "nReturned" : 2,
                "executionTimeMillisEstimate" : 0,
                "works" : 4,
                "advanced" : 2,
                "needTime" : 0,
                "needYield" : 0,
                "saveState" : 0,
                "restoreState" : 0,
                "isEOF" : 1,
                "invalidates" : 0,
                "docsExamined" : 2,
                "alreadyHasObj" : 0,
                "inputStage" : {
                        "stage" : "IXSCAN",
                        "nReturned" : 2,
                        "executionTimeMillisEstimate" : 0,
                        "works" : 3,
                        "advanced" : 2,
                        "needTime" : 0,
                        "needYield" : 0,
                        "saveState" : 0,
                        "restoreState" : 0,
                        "isEOF" : 1,
                        "invalidates" : 0,
                        "keyPattern" : {
                                "provider" : 1,
                                "refreshToken" : 1
                        },
                        "indexName" : "provider_1_refreshToken_1",
                        "isMultiKey" : false,
                        "isUnique" : false,
                        "isSparse" : false,
                        "isPartial" : true,
                        "indexVersion" : 1,
                        "direction" : "forward",
                        "indexBounds" : {
                                "provider" : [
                                        "[\"gitlab\", \"gitlab\"]"
                                ],
                                "refreshToken" : [
                                        "[null, null]"
                                ]
                        },
                        "keysExamined" : 2,
                        "dupsTested" : 0,
                        "dupsDropped" : 0,
                        "seenInvalidated" : 0
                }
        },
        "ts" : ISODate("2022-05-18T00:42:14.276Z"),
        "client" : "172.18.0.1",
        "allUsers" : [ ],
        "user" : ""
}
// ...
Edited by Eric Eastwood

Merge request reports