mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
fix: don't crash if something wrong with database
This commit is contained in:
parent
efc1799674
commit
2dcc822e48
2 changed files with 39 additions and 3 deletions
|
@ -10,9 +10,11 @@
|
||||||
#include "entities.h"
|
#include "entities.h"
|
||||||
#include "ayu/libs/sqlite/sqlite_orm.h"
|
#include "ayu/libs/sqlite/sqlite_orm.h"
|
||||||
|
|
||||||
|
#include "base/unixtime.h"
|
||||||
|
|
||||||
using namespace sqlite_orm;
|
using namespace sqlite_orm;
|
||||||
|
|
||||||
auto storage = make_storage("ayugram.db",
|
auto storage = make_storage("./tdata/ayudata.db",
|
||||||
make_table("DeletedMessage",
|
make_table("DeletedMessage",
|
||||||
make_column("userId", &DeletedMessage::userId),
|
make_column("userId", &DeletedMessage::userId),
|
||||||
make_column("dialogId", &DeletedMessage::dialogId),
|
make_column("dialogId", &DeletedMessage::dialogId),
|
||||||
|
@ -97,7 +99,41 @@ namespace AyuDatabase
|
||||||
|
|
||||||
void initialize()
|
void initialize()
|
||||||
{
|
{
|
||||||
storage.sync_schema();
|
// move to `tdata` from legacy version
|
||||||
|
if (std::filesystem::exists("ayugram.db")) {
|
||||||
|
try {
|
||||||
|
std::filesystem::rename("ayugram.db", "./tdata/ayudata.db");
|
||||||
|
}
|
||||||
|
catch (std::filesystem::filesystem_error &e) {
|
||||||
|
LOG(("Failed to move database: %1").arg(e.what()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
storage.sync_schema();
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
auto time = base::unixtime::now();
|
||||||
|
|
||||||
|
LOG(("Failed to sync database schema"));
|
||||||
|
LOG(("Moving current database just in case"));
|
||||||
|
|
||||||
|
if (std::filesystem::exists("./tdata/ayudata.db")) {
|
||||||
|
std::filesystem::rename("./tdata/ayudata.db", QString("./tdata/ayudata_%1.db").arg(time).toStdString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (std::filesystem::exists("./tdata/ayudata.db-shm")) {
|
||||||
|
std::filesystem::rename("./tdata/ayudata.db-shm",
|
||||||
|
QString("./tdata/ayudata_%1.db-shm").arg(time).toStdString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (std::filesystem::exists("./tdata/ayudata.db-wal")) {
|
||||||
|
std::filesystem::rename("./tdata/ayudata.db-wal",
|
||||||
|
QString("./tdata/ayudata_%1.db-wal").arg(time).toStdString());
|
||||||
|
}
|
||||||
|
|
||||||
|
storage.sync_schema();
|
||||||
|
}
|
||||||
|
|
||||||
storage.begin_transaction();
|
storage.begin_transaction();
|
||||||
storage.commit();
|
storage.commit();
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 312da65aa0c5bea95b39a48f6066d49df7bcf4f9
|
Subproject commit 9bf40511b96b0b46311f3d29686846bcf44ade3f
|
Loading…
Add table
Reference in a new issue