First time use application initialisation


#1

The first time my application is used on a given device, I need to perform local database initialisation (this could be for example sql schema or no-sql persistent queries initialisation). This needs to be done before user we’ll be able to use application for the first time but also at the moment when all libraries will be loaded and accessible for me.

Where (when) should I perform such initialisation and how can I guarantee that it will be never fired again, unless user re-installs the application.

(I’m using Ionic2 with TypeScript if it does matter)

Thank you in advance for all ideas.


#2

There are probably several options for each aspect of your question, but a suggestion for each:

When to do it? In the platform.ready().then bit that is in application constructors of Ionic starter templates.

How to make sure it only happens once? Put a version number somewhere in your database schema. SELECT it. If it exists, the database has been initialized. If you get an error saying there are no rows found, then you need to do the initialization.


#3

do it in your App - defintion. create a special service for that --> this checks if the init-stuff was done before (check if table exists and so on). The service can hold something like an EventEmitter to notify other parts in the app, if initialisation has finished. So Logic, which depends on the initialisation is only called if everything is ready.