3 Replies Latest reply on Oct 13, 2014 11:11 PM by Kutir Mobility

    Issues with fixed schema database migrations

    Marcus Atkins

      Hi all,


      Every time I make changes to my database on the device I run into a lot of issue using on_migrate_source. I may be misunderstanding something.


      I have a fixed schema model which I am adding a new field (location_code).


      1. I add   "property :location_code, :string" to the model

      2. I change set :schema_version from '1.2' to '1.3'

      3. I create the following code in the on_migrate_source:

                if new_src['name'] == 'PurchaseOrderLineReceipts' && old_version == '1.2'

                      db = Rho::RHO.get_src_db(new_src['name'])

                      db.execute_sql("ALTER TABLE #{new_src['name']} ADD COLUMN location_code VARCHAR DEFAULT null")        

                      return true


      4. I stick a break point on the line that says 'return true' and I do a manual SQL select ("SELECT * FROM PurchaseOrderLineReceipts") and I get a field that says :location_code => nil (this is what I expect)

      5. I continue using the app, I get to a point where it does an insert and I get the following error:

           #<ArgumentError: could not prepare statement: 1; Message: table PurchaseOrderLineReceipts has no column named location_code>

      6. I do a manual select again and now there is no location_code.


      My code is very similar to that of the sample code in the docs so I'm unsure what I am doing wrong. It is almost like it does the migration then rolls back?? Getting very very frustrated with this database migration crap, as either I do not understand correctly or the RhoMobile functionality is not robust at all.