-
Notifications
You must be signed in to change notification settings - Fork 2
[MS-1244] Adding proper migration to updated ENROLMENT_V4 event #1463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alexandr-simprints
merged 8 commits into
release/2025.4.0
from
MS-1244-version-hops-incorrect-event-structure-after-sid-updates
Nov 12, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7dcd958
[MS-1243] 'externalCredentialIds' field was added in EnrolmentEventV4…
alexandr-simprints a65cbcc
[MS-1244] 'externalCredentialIds' field was added in EnrolmentEventV4…
alexandr-simprints 2112892
[MS-1244] changing Enrolment event search pattern
alexandr-simprints 5def673
[MS-1244] Updating EventMigrationTest to include EventMigration16to17
alexandr-simprints 5b32542
[MS-1244] Changing log level to 'error' in EventUpSyncTask::getClosed…
alexandr-simprints b41038a
[MS-1244] Updating migration tests from 16 to 17
alexandr-simprints 39bed4f
[MS-1244] When migrating from Event DB version 16 to 17, using JSONOb…
alexandr-simprints b7b4f66
[MS-1244] Updating test consistency and documentation
alexandr-simprints File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
infra/events/schemas/com.simprints.infra.events.event.local.EventRoomDatabase/17.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| { | ||
| "formatVersion": 1, | ||
| "database": { | ||
| "version": 17, | ||
| "identityHash": "d5dd0e6fc8f6d48c5f58e7b191bc8d3d", | ||
| "entities": [ | ||
| { | ||
| "tableName": "DbEvent", | ||
| "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `type` TEXT NOT NULL, `projectId` TEXT, `scopeId` TEXT, `eventJson` TEXT NOT NULL, `createdAt_unixMs` INTEGER NOT NULL, `createdAt_isTrustworthy` INTEGER NOT NULL, `createdAt_msSinceBoot` INTEGER, PRIMARY KEY(`id`))", | ||
| "fields": [ | ||
| { | ||
| "fieldPath": "id", | ||
| "columnName": "id", | ||
| "affinity": "TEXT", | ||
| "notNull": true | ||
| }, | ||
| { | ||
| "fieldPath": "type", | ||
| "columnName": "type", | ||
| "affinity": "TEXT", | ||
| "notNull": true | ||
| }, | ||
| { | ||
| "fieldPath": "projectId", | ||
| "columnName": "projectId", | ||
| "affinity": "TEXT" | ||
| }, | ||
| { | ||
| "fieldPath": "scopeId", | ||
| "columnName": "scopeId", | ||
| "affinity": "TEXT" | ||
| }, | ||
| { | ||
| "fieldPath": "eventJson", | ||
| "columnName": "eventJson", | ||
| "affinity": "TEXT", | ||
| "notNull": true | ||
| }, | ||
| { | ||
| "fieldPath": "createdAt.unixMs", | ||
| "columnName": "createdAt_unixMs", | ||
| "affinity": "INTEGER", | ||
| "notNull": true | ||
| }, | ||
| { | ||
| "fieldPath": "createdAt.isTrustworthy", | ||
| "columnName": "createdAt_isTrustworthy", | ||
| "affinity": "INTEGER", | ||
| "notNull": true | ||
| }, | ||
| { | ||
| "fieldPath": "createdAt.msSinceBoot", | ||
| "columnName": "createdAt_msSinceBoot", | ||
| "affinity": "INTEGER" | ||
| } | ||
| ], | ||
| "primaryKey": { | ||
| "autoGenerate": false, | ||
| "columnNames": [ | ||
| "id" | ||
| ] | ||
| } | ||
| }, | ||
| { | ||
| "tableName": "DbEventScope", | ||
| "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `projectId` TEXT NOT NULL, `type` TEXT NOT NULL, `payloadJson` TEXT NOT NULL, `start_unixMs` INTEGER NOT NULL, `start_isTrustworthy` INTEGER NOT NULL, `start_msSinceBoot` INTEGER, `end_unixMs` INTEGER, `end_isTrustworthy` INTEGER, `end_msSinceBoot` INTEGER, PRIMARY KEY(`id`))", | ||
| "fields": [ | ||
| { | ||
| "fieldPath": "id", | ||
| "columnName": "id", | ||
| "affinity": "TEXT", | ||
| "notNull": true | ||
| }, | ||
| { | ||
| "fieldPath": "projectId", | ||
| "columnName": "projectId", | ||
| "affinity": "TEXT", | ||
| "notNull": true | ||
| }, | ||
| { | ||
| "fieldPath": "type", | ||
| "columnName": "type", | ||
| "affinity": "TEXT", | ||
| "notNull": true | ||
| }, | ||
| { | ||
| "fieldPath": "payloadJson", | ||
| "columnName": "payloadJson", | ||
| "affinity": "TEXT", | ||
| "notNull": true | ||
| }, | ||
| { | ||
| "fieldPath": "createdAt.unixMs", | ||
| "columnName": "start_unixMs", | ||
| "affinity": "INTEGER", | ||
| "notNull": true | ||
| }, | ||
| { | ||
| "fieldPath": "createdAt.isTrustworthy", | ||
| "columnName": "start_isTrustworthy", | ||
| "affinity": "INTEGER", | ||
| "notNull": true | ||
| }, | ||
| { | ||
| "fieldPath": "createdAt.msSinceBoot", | ||
| "columnName": "start_msSinceBoot", | ||
| "affinity": "INTEGER" | ||
| }, | ||
| { | ||
| "fieldPath": "endedAt.unixMs", | ||
| "columnName": "end_unixMs", | ||
| "affinity": "INTEGER" | ||
| }, | ||
| { | ||
| "fieldPath": "endedAt.isTrustworthy", | ||
| "columnName": "end_isTrustworthy", | ||
| "affinity": "INTEGER" | ||
| }, | ||
| { | ||
| "fieldPath": "endedAt.msSinceBoot", | ||
| "columnName": "end_msSinceBoot", | ||
| "affinity": "INTEGER" | ||
| } | ||
| ], | ||
| "primaryKey": { | ||
| "autoGenerate": false, | ||
| "columnNames": [ | ||
| "id" | ||
| ] | ||
| } | ||
| } | ||
| ], | ||
| "setupQueries": [ | ||
| "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", | ||
| "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'd5dd0e6fc8f6d48c5f58e7b191bc8d3d')" | ||
| ] | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...s/src/main/java/com/simprints/infra/events/event/local/migrations/EventMigration16to17.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package com.simprints.infra.events.event.local.migrations | ||
|
|
||
| import androidx.room.migration.Migration | ||
| import androidx.sqlite.db.SupportSQLiteDatabase | ||
| import com.simprints.core.tools.extentions.getStringWithColumnName | ||
| import com.simprints.infra.logging.LoggingConstants.CrashReportTag.MIGRATION | ||
| import com.simprints.infra.logging.Simber | ||
| import org.json.JSONArray | ||
| import org.json.JSONObject | ||
|
|
||
| /** | ||
| * Starting from 2025.4.0, EnrolmentEventV4 requires the `externalCredentialIds` field. | ||
| * This migration adds an empty `externalCredentialIds` array field to the EnrolmentEventV4 event | ||
| * | ||
| * This migration adds: | ||
| * "externalCredentialIds": [], | ||
| * to the payload object. | ||
| */ | ||
| internal class EventMigration16to17 : Migration(16, 17) { | ||
| override fun migrate(db: SupportSQLiteDatabase) { | ||
| Simber.i("Migrating room db from schema 16 to schema 17.", tag = MIGRATION) | ||
| migrateEnrolmentEventJson(db) | ||
| Simber.i("Migration from schema 16 to schema 17 done.", tag = MIGRATION) | ||
| } | ||
|
|
||
| private fun migrateEnrolmentEventJson(database: SupportSQLiteDatabase) { | ||
| val eventsQuery = database.query( | ||
| "SELECT * FROM $DB_EVENT_ENTITY WHERE type = ?", | ||
| arrayOf(EVENT_TYPE_ENROLMENT_V4), | ||
| ) | ||
| eventsQuery.use { cursor -> | ||
| while (cursor.moveToNext()) { | ||
| val id = cursor.getStringWithColumnName("id") ?: continue | ||
| val jsonData = cursor.getStringWithColumnName(DB_EVENT_JSON_FIELD) ?: continue | ||
|
|
||
| try { | ||
| val jsonObject = JSONObject(jsonData) | ||
| val payload = jsonObject.optJSONObject(PAYLOAD_JSON_FIELD) ?: continue | ||
|
|
||
| // Only adding if 'externalCredentialIds' field doesn't exist | ||
| if (!payload.has(EXTERNAL_CREDENTIAL_IDS_JSON_FIELD)) { | ||
| payload.put(EXTERNAL_CREDENTIAL_IDS_JSON_FIELD, JSONArray()) | ||
| val migratedJson = jsonObject.toString() | ||
| database.execSQL( | ||
| "UPDATE $DB_EVENT_ENTITY SET $DB_EVENT_JSON_FIELD = ? WHERE id = ?", | ||
| arrayOf(migratedJson, id), | ||
| ) | ||
| } | ||
| } catch (e: Exception) { | ||
| Simber.e( | ||
| "Failed to migrate room db from schema 16 to schema 17.", | ||
| e, | ||
| tag = MIGRATION, | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| private const val DB_EVENT_ENTITY = "DbEvent" | ||
| private const val DB_EVENT_JSON_FIELD = "eventJson" | ||
| private const val EVENT_TYPE_ENROLMENT_V4 = "ENROLMENT_V4" | ||
| private const val EXTERNAL_CREDENTIAL_IDS_JSON_FIELD = "externalCredentialIds" | ||
| private const val PAYLOAD_JSON_FIELD = "payload" | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.