handle bookmark delete loading state

This commit is contained in:
2025-05-07 16:57:09 +01:00
parent e87a6586b6
commit 9f00c9bb29
7 changed files with 107 additions and 31 deletions

View File

@@ -28,6 +28,12 @@ CREATE TABLE IF NOT EXISTS bookmarks(
url TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS tags(
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
bookmark_id TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS sessions(
session_id TEXT NOT NULL,
user_id TEXT NOT NULL,
@@ -54,23 +60,26 @@ function migrateDatabase() {
createMetadataTableQuery.run()
const schemaVersionQuery = db.query("SELECT value FROM metadata WHERE key = 'schema_version'")
const setSchemaVersionQuery = db.query("UPDATE metadata SET value = $schemaVersion WHERE key = 'schema_version'")
const setSchemaVersionQuery = db.query("INSERT OR REPLACE INTO metadata VALUES ('schema_version', $schemaVersion)")
const row = schemaVersionQuery.get()
let currentVersion: number
if (row) {
currentVersion = (row as { value: number }).value
console.log(`Migrating database from version ${currentVersion} to version ${SCHEMA_VERSION}...`)
} else {
currentVersion = -1
console.log("Initializing database...")
}
if (currentVersion < SCHEMA_VERSION) {
if (currentVersion < 0) {
console.log("Initializing database...")
} else {
console.log(`Migrating database from version ${currentVersion} to version ${SCHEMA_VERSION}...`)
}
executeMigrations(migrations.slice(currentVersion + 1, SCHEMA_VERSION + 1))
setSchemaVersionQuery.run({ schemaVersion: SCHEMA_VERSION })
console.log("Database successfully migrated!")
} else {
} else if (currentVersion > SCHEMA_VERSION) {
console.error("Rolling back database to a previous version is unsupported. Are you trying to downgrade MARKONE?")
}
}