Skip to content

Migrate EventHistory database to Application Support directory#1186

Merged
sbenedicadb merged 11 commits intoadobe:dev-v5.7.0from
sbenedicadb:migrate-eventhistory-database
Sep 17, 2025
Merged

Migrate EventHistory database to Application Support directory#1186
sbenedicadb merged 11 commits intoadobe:dev-v5.7.0from
sbenedicadb:migrate-eventhistory-database

Conversation

@sbenedicadb
Copy link
Copy Markdown
Member

@sbenedicadb sbenedicadb commented Sep 11, 2025

Description

  • add code to migrate EventHistory database out of Caches directory
    • old path: [APP_DIR]/Library/Caches/com.adobe.eventHistory
    • new path: [APP_DIR]/Library/Application Support/com.adobe.aep.db/com.adobe.eventHistory
    • all migration code is contained in new file EventHistoryDatabaseMigrator.swift
    • Migration code is executed when the EventHistoryDatabase is initialized
  • moved EventHistory initialization to background thread on eventHubQueue queue
  • added support for providing a subdirectory to SQLiteWrapper's connect function
  • added an extension to FileManager to allow easy creation of directories when they don't exist

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

static let dbName = "com.adobe.eventHistory"
static let dbSubdirectoryName = "com.adobe.aep.db"
static let dbNameWithSubdirectory = dbSubdirectoryName + "/" + dbName
static let dbFilePath: FileManager.SearchPathDirectory = .applicationSupportDirectory
Copy link
Copy Markdown
Contributor

@praveek praveek Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: dbDirectory

static let dbSubdirectoryName = "com.adobe.aep.db"
static let dbNameWithSubdirectory = dbSubdirectoryName + "/" + dbName
static let dbFilePath: FileManager.SearchPathDirectory = .applicationSupportDirectory
static let legacyDbFilePath: FileManager.SearchPathDirectory = .cachesDirectory
Copy link
Copy Markdown
Contributor

@praveek praveek Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: legacyDbDirectory

/// - subDirectory: a sub directory to `databaseFilePath` that contains the database
/// - databaseName: the database name
/// - Returns: the database connection
public static func connect(databaseFilePath: FileManager.SearchPathDirectory, subDirectory: String, databaseName: String) -> OpaquePointer? {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

databaseFilePath is confusing. Let’s rename it to databaseDirectoryPath, even though it deviates from the current function’s naming convention, since we may eventually migrate all extensions to use this function.

@sbenedicadb sbenedicadb marked this pull request as ready for review September 16, 2025 21:11
@sbenedicadb sbenedicadb requested a review from praveek September 17, 2025 16:52
let fileManager = FileManager.default

// most common scenario is that the database has already been migrated, so check that first
if let existingNewDbUrl = fileManager.urls(for: EventHistoryConstants.applicationSupportDirectory, in: .userDomainMask).first?.appendingPathComponent(EventHistoryConstants.dbNameWithSubdirectory) {
Copy link
Copy Markdown
Contributor

@praveek praveek Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: More readable if you use the same pattern as line 29.

if let existingNewDbUrl = ....., fileExists(atPath: existingNewDbUrl.path) {
    return
}


clearCachedItems(cacheItems, in: .cachesDirectory)

let migratedEventHistoryDb = [(name: "com.adobe.aep.db/com.adobe.eventHistory", isDirectory: false)]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Should be simpler to delete the entire directory

@sbenedicadb sbenedicadb changed the base branch from dev-v5.6.3 to dev-v5.7.0 September 17, 2025 22:01
@sbenedicadb sbenedicadb merged commit 72fa8ed into adobe:dev-v5.7.0 Sep 17, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants