capacitor-community / sqlite

Community plugin for native & electron SQLite databases
MIT License
418 stars 103 forks source link

Migration not working on iOS #546

Closed tradingproject19 closed 1 week ago

tradingproject19 commented 1 week ago

Describe the bug First of all thank you so much for this awesome plugin. We have an issue with iOS. We were using cordova sqlite plugin and were using the default location, when I migrated to capacitor sqlite, it seems to work on Android and creates a copy of our database file, but when I run the app in iOS it does not seems to work.

I am passing the "default" to getMigratableDbList method but it does not pick the database. I checked on iOS simulator folder and our database exists in "/Library/LocalDatabase/ourdb.db

Is the "default" supposed to pick from LocalDatabase folder or am I missing something?

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior Should create a copy on iOS

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

tradingproject19 commented 1 week ago

I have changed the path to Library/LocalDatabase for iOS and it seems to be working fine now. Default path uses Documents folder inside app on iOS.

public async migrateFromCordova() {
  try {
    let path = Capacitor.getPlatform() === 'ios' ? 'Library/LocalDatabase' : 'default';
    let dbSchema = await this.sqliteService.getMigratableDbList(path);
    await this.sqliteService.addSQLiteSuffix(path, dbSchema.values);
    await this.sqliteService.deleteOldDatabases(path);
    return true;
  }
  catch (ex) {
    console.log(ex, 'Unable to migrate to capacitor! migrateFromCordova');
    return true;
  }
}
jepiqueau commented 1 week ago

@tradingproject19 Yes this is what is written in the doc MigratingCordovaDatabases.md. so i assume that i can close the issue

tradingproject19 commented 1 week ago

It's working on simulator but not on physical device. :(

I will go to my office tomorrow and troubleshoot it. I think path on device may be different than path on simulator.

Thank you for your help.