@@ -6,10 +6,7 @@ import { LighthouseAISDK, EnhancedAccessCondition } from "@lighthouse-tooling/sd
66import { UploadResult , DownloadResult , AccessCondition , Dataset } from "@lighthouse-tooling/types" ;
77import { Logger } from "@lighthouse-tooling/shared" ;
88import { ILighthouseService , StoredFile } from "./ILighthouseService.js" ;
9- import {
10- IStorageService ,
11- InMemoryStorageService ,
12- } from "../storage/InMemoryStorageService.js" ;
9+ import { IStorageService , InMemoryStorageService } from "../storage/InMemoryStorageService.js" ;
1310import { createStorageService } from "../storage/StorageFactory.js" ;
1411
1512export class LighthouseService implements ILighthouseService {
@@ -53,6 +50,10 @@ export class LighthouseService implements ILighthouseService {
5350 if ( ! this . storageInitialized ) {
5451 try {
5552 const newStorage = await createStorageService ( this . dbPath ) ;
53+
54+ // Migrate any data from in-memory storage to new storage
55+ this . migrateStorage ( this . storage , newStorage ) ;
56+
5657 // Close old in-memory storage
5758 this . storage . close ( ) ;
5859 this . storage = newStorage ;
@@ -73,6 +74,37 @@ export class LighthouseService implements ILighthouseService {
7374 }
7475 }
7576
77+ /**
78+ * Migrate data from old storage to new storage
79+ * This ensures no data is lost when upgrading from in-memory to SQLite
80+ */
81+ private migrateStorage ( oldStorage : IStorageService , newStorage : IStorageService ) : void {
82+ try {
83+ // Migrate files
84+ const files = oldStorage . listFiles ( ) ;
85+ for ( const file of files ) {
86+ newStorage . saveFile ( file ) ;
87+ }
88+
89+ // Migrate datasets
90+ const { datasets } = oldStorage . listDatasets ( ) ;
91+ for ( const dataset of datasets ) {
92+ newStorage . saveDataset ( dataset ) ;
93+ }
94+
95+ if ( files . length > 0 || datasets . length > 0 ) {
96+ this . logger . info ( "Migrated data from in-memory to persistent storage" , {
97+ fileCount : files . length ,
98+ datasetCount : datasets . length ,
99+ } ) ;
100+ }
101+ } catch ( error ) {
102+ this . logger . warn ( "Failed to migrate some data during storage upgrade" , {
103+ error : error instanceof Error ? error . message : String ( error ) ,
104+ } ) ;
105+ }
106+ }
107+
76108 /**
77109 * Set up event listeners for SDK events
78110 */
0 commit comments