src/CRUD.SqliteAdapter.js
/**
         * Run migrations for a table if the version stored in localStorage is out of sync.
         * All tables created by CreateReadUpdateDelete.js are versioned this way.
         * For more info on migrations see the docs.
         * @return {void} void
         */
Run migrations for a table if the version stored in localStorage is out of sync.
All tables created by CreateReadUpdateDelete.js are versioned this way.
For more info on migrations see the docs.
@return {void} void
Run migrations for a table if the version stored in localStorage is out of sync . All tables created by CreateReadUpdateDelete . js are versioned this way . For more info on migrations see the docs . @return { void } void
function runMigrations() {
            return Promise.all(Object.keys(CRUD.EntityManager.entities).map(function(entityName) {
                var entity = CRUD.EntityManager.entities[entityName];
                if (entity.migrations) {
                    var currentVersion = !localStorage.getItem('database.version.' + entity.table) ? 1 : parseInt(localStorage.getItem('database.version.' + entity.table), 10);
                    if (isNaN(currentVersion)) {
                        currentVersion = 1;
                    }
                    var highestVersion = Math.max.apply(Math, Object.keys(entity.migrations));
                    if (currentVersion == highestVersion) return;
                    return Promise.all(Object.keys(entity.migrations).map(function(version) {
                        if (parseInt(version) > currentVersion) {
                            return Promise.all(entity.migrations[version].map(function(migration) {
                                CRUD.log('Executing migration: ', migration);
                                return db.execute(migration).then(function(result) {
                                    CRUD.log("Migration success!", result);
                                    return true;
                                }, function(err) {
                                    throw "Migration " + version + " failed for entity " + entityName;
                                });
                            })).then(function() {
                                CRUD.log("All migrations executed for version ", version);
                                localStorage.setItem('database.version.' + entity.table, version);
                                return true;
                            });
                        }
                        return true;
                    }));
                }
            }));
        }
function runMigrations ( ) { return Promise . all ( Object . keys ( CRUD . EntityManager . entities ) . map ( function ( entityName ) { var entity = CRUD . EntityManager . entities [ entityName ] ; if ( entity . migrations ) { var currentVersion = ! localStorage . getItem ( 'database.version.' + entity . table ) ? 1 : parseInt ( localStorage . getItem ( 'database.version.' + entity . table ) , 10 ) ; if ( isNaN ( currentVersion ) ) { currentVersion = 1 ; } var highestVersion = Math . max . apply ( Math , Object . keys ( entity . migrations ) ) ; if ( currentVersion == highestVersion ) return ; return Promise . all ( Object . keys ( entity . migrations ) . map ( function ( version ) { if ( parseInt ( version ) > currentVersion ) { return Promise . all ( entity . migrations [ version ] . map ( function ( migration ) { CRUD . log ( 'Executing migration: ' , migration ) ; return db . execute ( migration ) . then ( function ( result ) { CRUD . log ( "Migration success!" , result ) ; return true ; } , function ( err ) { throw "Migration " + version + " failed for entity " + entityName ; } ) ; } ) ) . then ( function ( ) { CRUD . log ( "All migrations executed for version " , version ) ; localStorage . setItem ( 'database.version.' + entity . table , version ) ; return true ; } ) ; } return true ; } ) ) ; } } ) ) ; }
Run migrations for a table if the version stored in localStorage is out of sync.
Run migrations for a table if the version stored in localStorage is out of sync .