0

I'm using SQLite.Swift and I'd like to know how to do to verify that the db still has the same schema when the application starts because on updtate, it's possible that the new application add columns in the table in which case I'm unable to use the existing db on the device.
I'll have to migrate/recreate the table.
How to do that please?

fralbo
  • 2,534
  • 4
  • 41
  • 73

1 Answers1

0

For tracking the database version, you can use the built in user-version variable that sqlite provides (sqlite does nothing with this variable, you are free to use it however you please). It starts at 0, and you can get/set this variable with the following sqlite statements:

> PRAGMA user_version;  
> PRAGMA user_version = 1;

See this answer which discuss your requirement including making schema changes after update

Community
  • 1
  • 1
Tony Vincent
  • 13,354
  • 7
  • 49
  • 68
  • ok thanks but this problem solves the quite easy way where we update from version 0 to version 1. If for any reason we update from version 0 to version 2, that could be problematic. I suppose it would be better to really check the schema with `PRAGMA table_info(tablename)` no? – fralbo Jul 21 '16 at 10:32