Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

database structure to update efficiently

hi folks,

imaging the follow scenario:
i have a sqlite-database for an iphone app with some "documents" as templates. the user is able to add his own templates too. now i want to update the program and the database. is there any chance to do so without overwriting the users data?
i thought about two different db but since this is an overhead it want to avoid this.

— asked October 25th 2010 by dev 1605
  • database
  • mobile
  • sql
0 Comments

2 Answers

  • Accepted Answer

    I was thinking this same thought.  Does Titanium let you delete files from your apps directory?  If so, I would think the code would flow like this.
    
    if (old_database_exists)
    insert into new_database (select * from old_database)
    delete old database
    
    — answered October 25th 2010 by Josh Lewis
    permalink
    1 Comment
    • so i will insert a flag in the database table which is true if it is userContent. so the statement's like:

      if (old_database_exists)
      insert into new_database (select * from old_database where flag=1)
      delete old_database

      — commented October 29th 2010 by dev 1605
  • When you're updating a production database, just like any other database app, you'll need to write SQL scripts to migrate your database to the newer version. Titanium doesn't provide any mechanism for doing this, but the practice of migrating production databases via SQL scripts is pretty common. You might consider adding database version information to your database and check that in your script, similar to how Ruby on Rails migrations work.

    — answered October 25th 2010 by Kevin Whinnery
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.