@@ -327,8 +327,8 @@ export abstract class SqlProviderBase extends NoSqlProvider.DbProvider {
327327 const indexIdentifierDictionary = _ . keyBy ( storeSchema . indexes , index => getIndexIdentifier ( storeSchema , index ) ) ;
328328 const indexMetaDictionary = _ . keyBy ( currentIndexMetas , meta => meta . key ) ;
329329
330- // find indices in the schema that did not exist before
331- const newIndices = _ . filter ( storeSchema . indexes , index =>
330+ // find which indices in the schema existed / did not exist before
331+ const [ newIndices , existingIndices ] = _ . partition ( storeSchema . indexes , index =>
332332 ! indexMetaDictionary [ getIndexIdentifier ( storeSchema , index ) ] ) ;
333333
334334 // find indices in the meta that do not exist in the new schema
@@ -470,10 +470,13 @@ export abstract class SqlProviderBase extends NoSqlProvider.DbProvider {
470470
471471 if ( doSqlInPlaceMigration ) {
472472 const sqlInPlaceMigrator = ( ) => {
473- return trans . runQuery ( 'INSERT INTO ' + storeSchema . name +
474- ' SELECT ' + [ 'nsp_pk' , 'nsp_data' , ...indexColumns ] . join ( ', ' ) +
475- ' FROM temp_' + storeSchema . name ) ;
473+ const columnsToCopy = [ 'nsp_pk' , 'nsp_data' ,
474+ ..._ . map ( existingIndices , index => getIndexIdentifier ( storeSchema , index ) )
475+ ] . join ( ', ' ) ;
476476
477+ return trans . runQuery ( 'INSERT INTO ' + storeSchema . name + '(' + columnsToCopy + ')' +
478+ ' SELECT ' + columnsToCopy +
479+ ' FROM temp_' + storeSchema . name ) ;
477480 } ;
478481
479482 tableQueries . push (
0 commit comments