Issues with fixed schema database migrations

M Marcus Atkins 3 years 5 months ago
1 1 0

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
    end
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:
     #
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.

Please Register or Login to post a reply

1 Replies

K Kutir Mobility

Hi Marcus
I was not able to reproduce the issue with the steps you have described. Do you think you can share a sample app with which i can reproduce the bug?

Visnupriya R
Kutir Mobility

CONTACT
Can’t find what you’re looking for?