6 Replies Latest reply on May 7, 2014 4:33 AM by Kutir Mobility

    Issues with on_migrate_source

    Rob Richard

      So I'm trying to get a handle on when the on_migrate_source is fired, and I'm not getting the results I expect.  Here is the scenario that I am using in rhosimulator:

       

      Test #1:

      Step 1: I delete the rhosimulator folder in the project.

      Step 2: I have a model (AppConfig) that is set :schema_version, '1.2', and in rhoconfig.txt, app_db_version = '1.6'

      Step 3: I run the app and populate contents of AppConfig accordingly.

      Step 4. I change in rhoconfig.txt, app_db_version = '1.7'

      Step 5. I set a breakpoint on the following code segment in application.rb:

        def on_migrate_source(old_version, new_src)

          # if we come across the potential to "upgrade" the AppConfig table, do not blow it away.

          if (new_src['name'] == "AppConfig")

            true # return true so that rhodes does not create the table automatically

          end

        end

      Step 6. I debug the app, and on_migrate_source is never fired.

       

      Test #2:

      Step 1: I delete the rhosimulator folder in the project.

      Step 2: I have a model (AppConfig) that is set :schema_version, '1.2', and in rhoconfig.txt, app_db_version = '1.6'

      Step 3: I run the app and populate contents of AppConfig accordingly.

      Step 4. I change (AppConfig) set :schema_version, '1.7', and in rhoconfig.txt, app_db_version = '1.7'

      Step 5. I set a breakpoint on the following code segment in application.rb:

        def on_migrate_source(old_version, new_src)

          # if we come across the potential to "upgrade" the AppConfig table, do not blow it away.

          if (new_src['name'] == "AppConfig")

            true # return true so that rhodes does not create the table automatically

          end

        end

      Step 6. I debug the app, and on_migrate_source is never fired.

       

      One would expect that since the version numbers have changed, that this function would fire.  Am I not using this properly?

        • Re: Issues with on_migrate_source
          Kutir Mobility

          Hi Richard

          We are trying to reproduce the steps locally.

          We will get back to you shortly.

           

          Visnupriya R

          Kutir Mobility

            • Re: Issues with on_migrate_source
              Kutir Mobility

              Rob,

              Data Migration supported for Fixed Schema only (IMHO). Your "AppConfig" model should use Fixed Schema.

              "on_migrate_source" get fired when you navigate to "AppConfig" model pages and change the version. So navigate to AppConfig model page and let us know what happen?

               

              It won't fire when a Rhodes app starts.

               

              Visnupriya R

              Kutir Mobility

                • Re: Issues with on_migrate_source
                  Rob Richard

                  The model is a fixed schema model.  I'm having a little difficulty understanding the second sentence however (about navigating to model pages and changing the version).  Could you please rephrase, clarify, and perhaps add more detail?

                    • Re: Issues with on_migrate_source
                      Kutir Mobility

                      Hi Rob

                      Please find the re-phrased text below. If required, please ask it again.

                       

                      1. Change the version in the AppConfig.rb (its your model file)

                      2. Navigate to your "AppConfig" model page ( any page that make use of AppConfig model)

                      3. When you navigate, the "on_migrate_source" method should get fired.

                       

                      Does it make sense now?

                       

                      VP

                      Kutir Mobility

                        • Re: Issues with on_migrate_source
                          Rob Richard

                          VP - I appreciate the input.  Here's the central core of the problem I'm running into: when I update my app and a user downloads the update, it blows away the existing database because the versions are different.  What I want to do is save the appconfig table - all of the other tables can be removed and rebuilt.  I was hoping that the "on_migrate_source" function could help me do that, but there is no opportunity to "navigate" to a page beforehand, so it appears that this function is pretty much useless.  Any ideas on how I can accomplish what it is I'm looking to do?

                           

                          Rob