Skip to content

Clarification about v3 migration: Is manual data migration required and must it remain in the codebase permanently? #1264

@hrastnik

Description

@hrastnik

What happened?

Hi

I'm currently planning a migration to AsyncStorage v3 and had a question about how existing data should be handled.

I read the migration guide here:
https://react-native-async-storage.github.io/3.0/migration-to-3/

From my understanding, the new v3 API uses createAsyncStorage() and introduces namespaced storage instances. However, it's not completely clear to me how existing data stored using the old API should be accessed or migrated.

My concern

If a user already has data stored with the previous API (@react-native-async-storage/async-storage v2), is there a way to access that data using the new v3 storage instance, or is a manual migration step required?

For example, I implemented the following migration logic:

const storage = createAsyncStorage("database");

const hasMigrated = await storage.getItem("__migrated__");
if (!hasMigrated) {
  const keys = await RNAsyncStorage.getAllKeys();
  if (keys.length > 0) {
    const entries = await RNAsyncStorage.getMany(keys);

    const nonNullEntries: Record<string, string> = {};
    for (const key in entries) {
      const value = entries[key];
      if (value != null) {
        nonNullEntries[key] = value;
      }
    }

    await storage.setMany(nonNullEntries);
    await RNAsyncStorage.removeMany(keys);
  }
  await storage.setItem("__migrated__", "true");
}

Questions

  1. Is this kind of manual migration approach the recommended way to move data from the old API to v3?
  2. Is there any way for the new v3 storage instance to read existing keys directly, or are they completely separate storage namespaces?
  3. If manual migration is required, does that mean this migration code needs to remain in the codebase indefinitely for users who might update from very old app versions?
  4. Are there any best practices recommended by the maintainers for handling this migration safely in production apps?

My main goal is to ensure users don't lose previously stored data when upgrading to v3.

Thanks in advance for any clarification!

Version

3

What platforms are you seeing this issue on?

  • Android
  • iOS
  • macOS
  • Windows
  • web

System Information

React Native 0.84.1

Steps to Reproduce

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingv3Related to version 3

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions