Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-2419

onMigration does not working with app crashing

      How frequently does the bug occur?

      Always

      Description

      The below error always occur when I try to migrate type of date to string.

      com.facebook.react.JavaScript (10): EXC_BAD_ACCESS (code=1, address=0x30)
      

      And I got this message from issue navigator on Xcode

      I've tested various migration cases, but I got the same error every time I did a migration that changed types.
      Here's I reffered for the migration

      I've also tried to clean up cache on yarn and watchman

      yarn cache clean
      rm -rf node_modules yarn.lock
      yarn
      watchman watch-del-all
      

      migration codes

      Unable to find source-code formatter for language: tsx. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      class Transaction extends Realm.Object<Transaction> {...}
      class Plan extends Realm.Object<Plan> {
        _id!: Realm.BSON.ObjectId;
        startAt!: string; // date to string
        endAt!: string; // date to string
        transactions!: Realm.List<Transaction>;
      
        static schema = {
          name: 'Plan',
          properties: {
            _id: 'objectId',
            startAt: 'string',
            endAt: 'string',
            transactions: 'Transaction[]',
          },
          primaryKey: '_id',
        };
      }
      class OldPlan extends Realm.Object<OldPlan> {
        _id!: Realm.BSON.ObjectId;
        startAt!: Date;
        endAt!: Date;
        transactions!: Realm.List<Transaction>;
      
        static schema = {
          name: 'Plan',
          properties: {
            _id: 'objectId',
            startAt: 'date',
            endAt: 'date',
            transactions: 'Transaction[]',
          },
          primaryKey: '_id',
        };
      }
      
      const REALM_SCHEME_VERSION = 2;
      const config: Realm.Configuration = {
        schema: [Currency, Category, Transaction, Plan],
        deleteRealmIfMigrationNeeded: false,
        schemaVersion: REALM_SCHEME_VERSION,
        onMigration(oldRealm, newRealm) {
          // 1 -> 2
          if (oldRealm.schemaVersion < REALM_SCHEME_VERSION) {
            // Plan
            const oldPlans = oldRealm.objects(OldPlan);
            const newPlans = newRealm.objects(Plan);
      
            oldPlans.forEach((oldPlan, pIdx) => {
              newPlans[pIdx].startAt = format(oldPlan.startAt, 'yyyy-MM-dd');
              newPlans[pIdx].endAt = format(oldPlan.endAt, 'yyyy-MM-dd');
            });
          }
        },
      };
      
      // Create a realm context
      export const {RealmProvider, useObject, useQuery, useRealm} =
        createRealmContext(config);
      

      Screenshot on Xcode

      Screenshot on simulator

      pacakge.json

      {
      "dependencies": {
          "@react-native-community/datetimepicker": "^6.4.2",
          "@react-native-firebase/analytics": "^18.0.0",
          "@react-native-firebase/app": "^18.0.0",
          "@react-native-firebase/firestore": "^18.0.0",
          "@react-navigation/native": "^6.0.8",
          "@react-navigation/native-stack": "^6.9.12",
          "@react-navigation/stack": "^6.2.0",
          "@realm/react": "^0.4.3",
          "axios": "^1.4.0",
          "date-fns": "^2.29.3",
          "date-fns-tz": "^2.0.0",
          "native-base": "^3.4.28",
          "react": "18.2.0",
          "react-native": "0.71.8",
          "react-native-bootsplash": "^4.7.1",
          "react-native-calendars": "^1.1294.0",
          "react-native-gesture-handler": "^2.9.0",
          "react-native-haptic-feedback": "^2.0.3",
          "react-native-reanimated": "^3.2.0",
          "react-native-safe-area-context": "^4.4.1",
          "react-native-screens": "^3.19.0",
          "react-native-svg": "^13.7.0",
          "react-native-svg-transformer": "^1.0.0",
          "react-native-vector-icons": "^9.2.0",
          "realm": "11.9.0",
          "recoil": "^0.7.7"
        },
        "devDependencies": {
          "@babel/core": "^7.12.9",
          "@babel/runtime": "^7.12.5",
          "@bam.tech/react-native-make": "^3.0.3",
          "@react-native-community/eslint-config": "^2.0.0",
          "@testing-library/jest-native": "^5.4.2",
          "@testing-library/react-native": "^12.1.2",
          "@tsconfig/react-native": "^2.0.2",
          "@types/jest": "^26.0.23",
          "@types/react": "^18.0.21",
          "@types/react-native": "^0.70.6",
          "@types/react-native-calendars": "^1.1264.3",
          "@types/react-native-vector-icons": "^6.4.13",
          "@types/react-test-renderer": "^18.0.0",
          "@types/realm": "^1.13.0",
          "@typescript-eslint/eslint-plugin": "^5.37.0",
          "@typescript-eslint/parser": "^5.37.0",
          "babel-jest": "^26.6.3",
          "eslint": "^7.32.0",
          "jest": "^29.2.1",
          "jest-config": "^26.6.3",
          "metro-react-native-babel-preset": "^0.73.7",
          "react-native-version": "^4.0.0",
          "react-test-renderer": "18.2.0",
          "typescript": "^4.8.3"
        }
      }
      

      Stacktrace & log output

      Unable to find source-code formatter for language: shell. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      com.facebook.react.JavaScript (10): EXC_BAD_ACCESS (code=1, address=0x30)
      

      Can you reproduce the bug?

      Always

      Reproduction Steps

      1. Add an onMigration function
      2. yarn ios or Run build on Xcode

      Version

      "realm": "11.9.0", "@realm/react": "^0.4.3"

      What services are you using?

      Local Database only

      Are you using encryption?

      No

      Platform OS and version(s)

      macOS 13.4, iOS 16.4

      Build environment

      System:
          OS: macOS 13.4
          CPU: (10) arm64 Apple M1 Pro
          Memory: 134.27 MB / 16.00 GB
          Shell: 5.9 - /bin/zsh
        Binaries:
          Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
          Yarn: 1.22.19 - ~/.nvm/versions/node/v18.16.0/bin/yarn
          npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
          Watchman: 2023.04.10.00 - /opt/homebrew/bin/watchman
        Managers:
          CocoaPods: 1.12.0 - /opt/homebrew/bin/pod
        SDKs:
          iOS SDK:
            Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
          Android SDK: Not Found
        IDEs:
          Android Studio: 2020.3 AI-203.7717.56.2031.7784292
          Xcode: 14.3.1/14E300c - /usr/bin/xcodebuild
        Languages:
          Java: 11.0.11 - /usr/bin/javac
        npmPackages:
          @react-native-community/cli: Not Found
          react: 18.2.0 => 18.2.0 
          react-native: 0.71.8 => 0.71.8 
          react-native-macos: Not Found
        npmGlobalPackages:
          *react-native*: Not Found
      

      Cocoapods version

      1.12.0

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: