Ionic Update - Storage returns null for data saved using old package

Hi,
for the update of an ionic app from 5.3.4 to 6.1.13, also the ionic storage package changed from @ionic/storage (version 2) to @ionic/storage-angular (version 3). The whole app works fine, however I am unable to get already saved data with the new storage-module. Saving / retrieving new data with the new storage module works just fine!

Tested with Andoird and IOS

Old App (Ionic 5)

Saving / retrieving data works fine:

package.json:

"@angular/core": "~9.1.6",
"@ionic/angular": "^5.3.4",
"@ionic/storage": "^2.3.1",

app.module:

import { IonicStorageModule } from '@ionic/storage';

@NgModule({
 ...
 imports: [
    IonicModule.forRoot(),
    IonicStorageModule.forRoot({
      name: '__mydb',
      driverOrder: ['sqlite', 'websql', 'indexeddb'],
    }),
    ...

New App (Ionic 6, new angular-storage module)
Saving / retrieving new data works fine, retrieving data that was stored using the old storage module (same key) does not work: it’s null

package.json:

"@angular/core": "^14.0.5",
"@ionic/angular": "^6.1.13",
"@ionic/storage-angular": "^3.0.6",

app.module:

import { Drivers } from '@ionic/storage';
import { IonicStorageModule } from '@ionic/storage-angular';

@NgModule({
    ...
    imports: [
     IonicStorageModule.forRoot({
       name: '__mydb',
       driverOrder: [CordovaSQLiteDriver._driver, Drivers.IndexedDB, Drivers.LocalStorage],
     }),
     ...

New App (Ionic 6, old storage module)

I even tried to downgrade to the old storage package (same version as in old app), still I am unable to retrieve data that was saved using the old app:

package.json:

"@angular/core": "^14.0.5",
"@ionic/angular": "^6.1.13",
"@ionic/storage": "2.3.1",

app.module:

import { IonicStorageModule } from '@ionic/storage';

 @NgModule({
   ...
   imports: [
    IonicStorageModule.forRoot({
      name: '__mydb',
      driverOrder: ['sqlite', 'websql', 'indexeddb'],
    }),
   ...

I would appreciate any insights / tips, the database name did not change and the data is still there, because if I install the old version again all data is retrieved successfully.

But If I try to get the data (same key) with the updated ionic app, regardless of old or new storage package, I can’t retrieve the data…

Thanks for the link, however I am not sure I can follow. The old app and the new app are not using the capacitor storage but the ionic storage, so I can’t use the migrate function of capacitor. Or are you suggesting I have to use capacitor storage?

The solution in the links suggests ti have the app use both storage options in the app to migrate

I believe Ionic Storage has been renamed to Capacitor storage

Either way, there is a migration needed and likely it has to be done by the developer

Thanks for the answer, I really appreciate it. However I am still confused, so I will try to explain it in a better way.

Yes, there is a migrate function for Capacitor and it has to be used if one upgrades from Capacitor version 2 to version 3, see 3 Guide - Updating Capacitor to 3.0:

  • Storage
  • Data migration required! The internal storage mechanism has changed and requires data migration. A convenience method has been added: migrate(). To update your app without affecting end users, call migrate() before any other methods.

Also the capacitor storage plugin has been renamed in version 4, see Updating from Capacitor 3 to Capacitor 4:

The @capacitor/storage plugin has been renamed to @capacitor/preferences to better reflect it’s usage. The API remains the same.

But for my app, the capacitor storage packages were never used (no @capacitor/storage) Instead the app used the "@ionic/storage": "2.3.1" and this was updated to "@ionic/storage-angular": "^3.0.6". They are different packages and ionic storage api does not have a migrate() function?

I hope now it is easier to understand where my confusion comes from…

Of course can install capacitor storage and make some tests, it just seems like far fetched?

@sts1909 did you get to the bottom of your issue - I’m having a similar(ish) issue after migrating to Capacitor 4 ?

Any luck on this? I’m running into the same issue.

Yes, A colleague of mine found the issue.

As it turned out, the old app never used the sqllite db, despite having the following configuration in app.module: driverOrder: ['sqlite', 'websql', 'indexeddb'], (see my initial post)

it was always just the indexeddb, so using driverOrder: [Drivers.IndexedDB], solved it in our case

Please double check your configuration and maybe just try with one driver at a time

1 Like

Thanks for the reply, I’ll give that a shot. I’ve also had trouble with the driver order ignoring Sqlite, so what you’re saying makes sense.