3 Replies Latest reply on Apr 16, 2014 11:28 AM by Rob Richard

    Saving data from one table using data migration

    Rob Richard

      When I update to new versions of my app, I would like to use the data migration feature (Rhomobile | Using Rhom in Ruby) to save the data from my "AppConfig" table.  What is the best method to do this?  Any sample code or psuedo code is greatly appreciated since the docs are a little on the sparse side.

        • Re: Saving data from one table using data migration
          Peter Arcuri

          You may find what you're looking for in one of the several RhoMobile sample apps posted at Github.

           

          https://github.com/rhomobile/rho-samples

          • Re: Saving data from one table using data migration
            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?