@@ -6,15 +6,17 @@ import {
6
6
RxDocument ,
7
7
toTypedRxJsonSchema ,
8
8
ExtractDocumentTypeFromTypedRxJsonSchema ,
9
- addRxPlugin
9
+ addRxPlugin ,
10
10
} from 'rxdb' ;
11
- import { getRxStorageDexie , RxStorageDexie } from 'rxdb/plugins/storage-dexie' ;
12
- import type { RxStorageMemory } from 'rxdb/plugins/storage-memory' ;
11
+ import { getRxStorageDexie } from 'rxdb/plugins/storage-dexie' ;
13
12
import { RxDBJsonDumpPlugin } from 'rxdb/plugins/json-dump' ;
14
13
import { TaskNode } from './types' ;
15
14
// TOOD: remove at some point in the future...
16
15
import { RxDBDevModePlugin } from 'rxdb/plugins/dev-mode' ;
17
16
import { RxDBMigrationSchemaPlugin } from 'rxdb/plugins/migration-schema' ;
17
+ /* This is used so that we can migrate from old rxdb version to new ones (currently from v14.X to v15.X) */
18
+ import { migrateStorage } from 'rxdb/plugins/migration-storage' ;
19
+
18
20
addRxPlugin ( RxDBDevModePlugin ) ;
19
21
addRxPlugin ( RxDBJsonDumpPlugin ) ;
20
22
addRxPlugin ( RxDBMigrationSchemaPlugin ) ;
@@ -224,19 +226,37 @@ export const collections = {
224
226
} ,
225
227
} ;
226
228
227
- export async function createTaskyonDatabase (
228
- name : string ,
229
- storage : RxStorageDexie | RxStorageMemory | undefined = undefined ,
230
- ) : Promise < TaskyonDatabase > {
231
- const newStorage = storage || getRxStorageDexie ( ) ;
229
+ export async function createTaskyonDatabase ( ) : Promise < TaskyonDatabase > {
230
+ const newStorage = getRxStorageDexie ( ) ;
232
231
const db : TaskyonDatabase =
233
232
await createRxDatabase < TaskyonDatabaseCollections > ( {
234
- name,
233
+ name : 'taskyondb_v15' ,
235
234
storage : newStorage ,
236
235
} ) ;
237
236
238
237
await db . addCollections ( collections ) ;
239
238
239
+ //here we do te migration from or old storage
240
+ import ( 'rxdb-old/plugins/storage-dexie' ) . then (
241
+ ( { getRxStorageDexie : getRxStorageDexieOld } ) => {
242
+ migrateStorage ( {
243
+ database : db as unknown as RxDatabase ,
244
+ /**
245
+ * Name of the old database,
246
+ * using the storage migration requires that the
247
+ * new database has a different name.
248
+ */
249
+ oldDatabaseName : 'taskyondb' ,
250
+ oldStorage : getRxStorageDexieOld ( ) , // RxStorage of the old database
251
+ batchSize : 500 , // batch size
252
+ parallel : false , // <- true if it should migrate all collections in parallel. False (default) if should migrate in serial
253
+ afterMigrateBatch : ( /*input: AfterMigrateBatchHandlerInput*/ ) => {
254
+ console . log ( 'storage migration: batch processed' ) ;
255
+ } ,
256
+ } ) ;
257
+ } ,
258
+ ) ;
259
+
240
260
return db ;
241
261
}
242
262
0 commit comments