这似乎是 Safari 中的一个升级错误,应该在 bugs.webkit.org 上提交。假设这将在那里修复,因为 Safari 团队在遇到严重错误时非常敏感。请存档!
至于解决方法,我建议重新创建数据库。将数据库复制到新数据库,将其删除,然后复制回来并删除中间副本。我没有验证下面的代码,所以你必须测试它。
function check_and_fix_IOS_10_3_upgrade_issue () {
return (somehowCheckIfWeNeedToDoThis) ?
recreateDatabase() : Promise.resolve();
}
function recreateDatabase () {
copyDatabase("dbName", "dbName_tmp").then(()=>{
return Dexie.delete("dbName");
}).then(()=>{
return copyDatabase("dbName_tmp", "dbName");
}).then(()=>{
return Dexie.delete("dbName_tmp");
});
}
function copyDatabase(fromDbName, toDbName) {
return new Dexie(fromDbName).open().then(db => {
let schema = db.tables.reduce((schema, table) => {
schema[table.name] = [table.schema.primKey.src]
.concat(table.schema.indexes.map(idx => idx.src))
.join(',');
}, {});
let dbCopy = new Dexie(toDbName);
dbCopy.version(db.verno).stores(schema);
return dbCopy.open().then(()=>{
// dbCopy is now successfully created with same version and schema as source db.
// Now also copy the data
return Promise.all(
db.tables.map(table =>
table.toArray().then(rows => dbCopy.table(table.name).bulkAdd(rows))));
}).finally(()=>{
db.close();
dbCopy.close();
});
})
}
关于“somehowCheckIfWeNeedToDoThis”,我无法准确回答该怎么做。也许用户代理嗅探+ cookie(固定时设置持久cookie,这样它就不会一遍又一遍地重新创建)。也许你会找到更好的解决方案。
然后在您打开数据库之前(可能在您的应用程序启动之前),您需要执行以下操作:
check_and_fix_IOS_10_3_upgrade_issue()
.then(()=>app.start())
.catch(err => {
// Display error, to user
});