How to setup lifecycle for interfacing with $sqlite database

I’m running into a corner case with my application that I’m not sure how to handle. When the app starts for the very first time,

        app.run(function ($rootScope, $ionicPlatform, $cordovaSQLite, $cordovaSplashscreen, $cordovaFile, $http) {

            var EmailModel = function () {
                this.subject = '';
                this.bodyText = '';
                this.from = '';
            };
            
            $ionicPlatform.ready(function () {
                if (window.cordova && window.cordova.plugins.Keyboard) {
                    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
                    // for form inputs)
                    cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

                    // Don't remove this line unless you know what you are doing. It stops the viewport
                    // from snapping when text inputs are focused. Ionic handles this internally for
                    // a much nicer keyboard experience.
                    cordova.plugins.Keyboard.disableScroll(true);
                }
                if (window.StatusBar) {
                    StatusBar.styleDefault();
                }

                $http.get('data/emails.json').success(function (results) {
                
                    db = $cordovaSQLite.openDB("phishing.db");
                    createTables($cordovaSQLite);
               
                    for (var i = 0; i < results.emails.length; i++) {
                        var emailModel = new EmailModel();
                        emailModel.bodyText = results.emails[i].message;
                        emailModel.from = results.emails[i].from;
                        emailModel.subject = results.emails[i].subject;
                        $rootScope.emailToInsert = emailModel;
                        addEmailToTable($cordovaSQLite, $rootScope);
                    }
                });
                $cordovaSplashscreen.hide();
            });
        })


        //function used to create database tables if they do not already exist
        function createTables($cordovaSQLite) {
            var query = "";

            //create tbl_phishing_email
            query = "DROP TABLE tbl_email"
            $cordovaSQLite.execute(db, query);

            query = "CREATE TABLE IF NOT EXISTS tbl_email (id integer primary key, " +
            "title text, " +
            "from_email text, " +
            "to_email text, " +
            "subject text, " +
            "description text, " +
            "body_text text, " +
            "body_image blob, " +
            "email_type text, " +
            "createdOn numeric, " +
            "lastUpdated numeric)";

            $cordovaSQLite.execute(db, query).then(function (res) {
                console.log("CREATED tbl_email");
            }, function (err) {
                console.log("ERROR WHEN CREATING tbl_phishing_email -> " + err.message);
            });
        }

        //function used to load information into datatables if the informaiton does not exist already
        function addEmailToTable($cordovaSQLite, $rootScope) {
          
           var  query = "INSERT INTO tbl_email (title, from_email, to_email, subject, description, body_text, body_image, email_type, createdOn, lastUpdated) VALUES (?,?,?,?,?,?,?,?,?,?)";
            
            $cordovaSQLite.execute(db, query, [null, $rootScope.emailToInsert.from, null, $rootScope.emailToInsert.subject, null, $rootScope.emailToInsert.bodyText, null, null, null, null]).then(function (res) {
                console.log("inserted ID -> " + res.insertId);
            }, function (err) {
                console.log(err.message);
            });
        }

I need this code to run as soon as the app starts up. No in my main controller I’m then subscribing to the ionicPlatform.ready() event and then selecting all the data again from the database like so:

//GameController (controllers.js)

 .controller('GameController', function ($scope, $ionicModal, $cordovaSQLite, $ionicPlatform, $cordovaClipboard, $ionicPopup) {
  $ionicPlatform.ready(function () {
            $scope.loadEmails();
        })

 $scope.loadEmails = function () {
        query = "SELECT title, " +
        "from_email, " +
        "to_email, " +
        "subject, " +
        "description, " +
        "body_text, " +
        "FROM tbl_email";

        var db = $cordovaSQLite.openDB("phishing.db");

        $cordovaSQLite.execute(db, query).then(function (response) {
            for (var i = 0; i < response.rows.length; i++) {
                var newEmailModel = new EmailModel();
                newEmailModel.subject = response.rows.item(i).subject;
                newEmailModel.from = response.rows.item(i).from_email;
                newEmailModel.bodyText = response.rows.item(i).body_text;
                emails.push(newEmailModel);
            }
        }, function (err) {
            console.log("ERROR WHEN GETTING EMAILS FROM tbl_phishing_email -> " + err.message);
        });
    }
})

I’ve observed a race condition that happens the first time the app is being installed on the simulator. What happens is controller.js is getting called first selecting all the data before the data has been inserted in the database which is done in app.js. On subsequent launches of the application, app.js will fire first and the controller will fire after which is what I want it to do. My question is how do I fix this the first time when the application is run on the simulator? Is there a better way to structure the code to avoid this problem from happening? The biggest thing I had to do to get the select statement to fire at all was wrap it in the ionicPlatform.ready() function. Any tips or help would be appreciated. Thanks!