|
|
@ -41,7 +41,9 @@ export async function initDB(){ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (realmDB === null){ |
|
|
|
let dbRef = realmDB; |
|
|
|
|
|
|
|
if (dbRef === null){ |
|
|
|
let schemaList = [ |
|
|
|
{schemaVersion: 0, schema: [System, User, Score], migration: Migrations.migratev0, encryptionKey: dbKey}, |
|
|
|
{schemaVersion: 1, schema: [System, User, Score], migration: Migrations.migratev1, encryptionKey: dbKey} |
|
|
@ -54,23 +56,24 @@ export async function initDB(){ |
|
|
|
} |
|
|
|
|
|
|
|
while (currentSchema < schemaList.length) { |
|
|
|
if (realmDB !== null) { |
|
|
|
realmDB.close(); |
|
|
|
if (dbRef !== null) { |
|
|
|
dbRef.close(); |
|
|
|
} |
|
|
|
|
|
|
|
realmDB = new Realm(schemaList[currentSchema]); |
|
|
|
dbRef = new Realm(schemaList[currentSchema]); |
|
|
|
currentSchema += 1; |
|
|
|
} |
|
|
|
|
|
|
|
if (realmDB === null) { |
|
|
|
realmDB = new Realm(schemaList[schemaList.length - 1]); |
|
|
|
if (dbRef === null) { |
|
|
|
dbRef = new Realm(schemaList[schemaList.length - 1]); |
|
|
|
} |
|
|
|
|
|
|
|
systemRepo = new SystemRepo(realmDB); |
|
|
|
userRepo = new UserRepo(realmDB); |
|
|
|
scoreRepo = new ScoreRepo(realmDB) |
|
|
|
systemRepo = new SystemRepo(dbRef); |
|
|
|
userRepo = new UserRepo(dbRef); |
|
|
|
scoreRepo = new ScoreRepo(dbRef) |
|
|
|
} |
|
|
|
|
|
|
|
let realmDB = dbRef; |
|
|
|
return realmDB; |
|
|
|
} catch (err) { |
|
|
|
console.log(err); |
|
|
|