feat: Migrate MPPersistence + DBMigrationController to Swift - #868
Conversation
PR SummaryHigh Risk Overview Adds Swift-owned persistence metadata and file I/O: Tests and mocks now import Reviewed by Cursor Bugbot for commit 3d9b5e4. Bugbot is set up for automated code reviews on this repo. Configure here. |
🐦 Swift Migration ProgressProduction implementation code at
Objective-C retained by design: Core SDK 5,855 (-5) · SDK kit infrastructure 385 · Standalone kits 0. This PR's code movement
How this is measured
Generated with |
📦 SDK Size Impact ReportMeasures how much the SDK adds to an app's size (with-SDK minus without-SDK).
➡️ SDK size impact change is minimal. Raw measurementsTarget branch (workstation/swift-migration): {"baseline_app_size_kb":84,"baseline_executable_size_bytes":75464,"with_sdk_app_size_kb":2256,"with_sdk_executable_size_bytes":76312,"sdk_impact_kb":2172,"sdk_executable_impact_bytes":848,"xcframework_size_kb":6880}This PR: {"baseline_app_size_kb":84,"baseline_executable_size_bytes":75464,"with_sdk_app_size_kb":2280,"with_sdk_executable_size_bytes":76312,"sdk_impact_kb":2196,"sdk_executable_impact_bytes":848,"xcframework_size_kb":6836} |
Fully convert MPSession, MPUpload, and MPMessage
c464e89 to
2f60018
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 2f60018. Configure here.
Chained UTF8String on temporary Swift NSStrings can dangle before sqlite3_prepare_v2, which can skip or crash queued-event migration. Prepare from a retained NSString so the SQL buffer stays valid. Empty MPSession init hardcoded userId 0 after the ObjC facade was removed. Read the stored MPID from user defaults, matching the previous persistence lookup.
206fa3a
into
workstation/swift-migration

What
Moves persistence schema logic, internal persistence models, and all persistence File I/O to Swift while retaining thin Objective-C controllers for SQLite operations.
Deletes the Objective-C implementations of:
MPSession
MPMessage
MPUpload
Their Swift replacements retain the existing Objective-C runtime names and selectors through @objc(MPSession), @objc(MPMessage), and @objc(MPUpload).
Persistence logic moved to Swift
MPPersistenceSchemaPRIVATE now owns:
Database versions and names
Paths and directory selection
Size limits
SQL statements and builders
Migration decisions
Legacy sidecar decisions
MPID table metadata
MPDatabaseMigrationLogicPRIVATE owns the SQL used to migrate records between database versions.
SQLite execution and row migration remain in Objective-C so raw SQLite pointers and Objective-C-only dependencies do not cross the module boundary.
Models moved fully to Swift
The Swift models preserve the existing behavior:
MPSession
Thread-safe properties
KVO notifications
Session timing and counter behavior
NSCopying
MPMessage
NSSecureCoding
JSON sanitization and truncation
NSCopying
MPUpload
Upload settings association
Serialization and copying
The Objective-C headers and implementations for these classes are removed.
File I/O and logger injection
Adds MPPersistenceFileSystemPRIVATE, which owns all persistence FileManager operations:
Database directory creation
Documents → Application Support migration
WAL, SHM, and journal sidecar migration
Legacy SessionNumber cleanup
Backup exclusion
Database deletion
Current and legacy path resolution
MPLog is injected from the existing MParticle logger, preserving current log-level and custom-logger behavior.
MPPersistenceController_PRIVATE and MPDatabaseMigrationController now delegate File I/O to this Swift implementation.
Behavior / API
Existing Objective-C runtime class names and selectors are preserved.
Published persistence signatures remain unchanged.
Database initialization and migration ordering is unchanged.
Failed directory migrations preserve the Documents database and continue using it.
Existing Application Support databases take precedence over legacy copies.
Orphan sidecars are removed rather than attached to another database.
No changelog changes; release automation handles them.
Validation
trunk check: clean for changed files.
iOS and tvOS simulator builds: succeeded.
Swift persistence File I/O tests: 9/9 passed.
Objective-C persistence integration tests: 62/62 passed.
Full Swift test suite: passed.
Full Objective-C suite passed