mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-15 20:26:53 +02:00
schema upgrade
This commit is contained in:
parent
c9016845c3
commit
6913c87d5c
|
@ -16,7 +16,7 @@ final class Config
|
|||
{
|
||||
refreshTokenFilePath = configDirName ~ "/refresh_token";
|
||||
statusTokenFilePath = configDirName ~ "/status_token";
|
||||
databaseFilePath = configDirName ~ "/items.db";
|
||||
databaseFilePath = configDirName ~ "/items.sqlite3";
|
||||
uploadStateFilePath = configDirName ~ "/resume_upload";
|
||||
userConfigFilePath = configDirName ~ "/config";
|
||||
}
|
||||
|
|
30
src/itemdb.d
30
src/itemdb.d
|
@ -33,21 +33,25 @@ final class ItemDatabase
|
|||
this(const(char)[] filename)
|
||||
{
|
||||
db = Database(filename);
|
||||
db.exec("CREATE TABLE IF NOT EXISTS item (
|
||||
id TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
type TEXT NOT NULL,
|
||||
eTag TEXT NOT NULL,
|
||||
cTag TEXT,
|
||||
mtime TEXT NOT NULL,
|
||||
parentId TEXT,
|
||||
crc32 TEXT,
|
||||
FOREIGN KEY (parentId) REFERENCES item (id) ON DELETE CASCADE
|
||||
)");
|
||||
db.exec("CREATE INDEX IF NOT EXISTS name_idx ON item (name)");
|
||||
if (db.getVersion() == 0) {
|
||||
db.exec("CREATE TABLE item (
|
||||
id TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
type TEXT NOT NULL,
|
||||
eTag TEXT NOT NULL,
|
||||
cTag TEXT,
|
||||
mtime TEXT NOT NULL,
|
||||
parentId TEXT,
|
||||
crc32 TEXT,
|
||||
FOREIGN KEY (parentId) REFERENCES item (id) ON DELETE CASCADE
|
||||
)");
|
||||
db.exec("CREATE INDEX name_idx ON item (name)");
|
||||
db.setVersion(itemDatabaseVersion);
|
||||
} else if (db.getVersion() != itemDatabaseVersion) {
|
||||
throw new Exception("The item database is incompatible, please resync manually");
|
||||
}
|
||||
db.exec("PRAGMA foreign_keys = ON");
|
||||
db.exec("PRAGMA recursive_triggers = ON");
|
||||
db.setVersion(itemDatabaseVersion);
|
||||
|
||||
insertItemStmt = db.prepare("INSERT OR REPLACE INTO item (id, name, type, eTag, cTag, mtime, parentId, crc32) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
updateItemStmt = db.prepare("
|
||||
|
|
|
@ -46,6 +46,14 @@ int main(string[] args)
|
|||
if (!exists(configDirName)) mkdir(configDirName);
|
||||
auto cfg = new config.Config(configDirName);
|
||||
cfg.init();
|
||||
|
||||
// upgrades
|
||||
if (exists(configDirName ~ "/items.db")) {
|
||||
remove(configDirName ~ "/items.db");
|
||||
log.log("Database schema changed, resync needed");
|
||||
resync = true;
|
||||
}
|
||||
|
||||
if (resync || logout) {
|
||||
log.log("Deleting the saved status ...");
|
||||
safeRemove(cfg.databaseFilePath);
|
||||
|
|
Loading…
Reference in a new issue