Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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");
- }).catch(err => {
- console.error (err);
- })
- }
- 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))));
- });
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement