feat(library): add sqlite-backed library sync and stats

BREAKING CHANGE: Library data is now stored in a database and will require an initial sync. Existing in-memory library data is no longer used.
This commit is contained in:
2025-10-01 20:02:57 -04:00
parent bdfd245b4e
commit 8391897f54
10 changed files with 783 additions and 19 deletions

View File

@@ -1,3 +1,5 @@
use tauri_plugin_sql::{Migration, MigrationKind};
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
#[tauri::command]
fn greet(name: &str) -> String {
@@ -6,8 +8,51 @@ fn greet(name: &str) -> String {
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
let migrations = vec![
Migration {
version: 1,
description: "create_library_tables",
sql: "
CREATE TABLE IF NOT EXISTS artists (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
path TEXT NOT NULL UNIQUE,
album_count INTEGER DEFAULT 0,
track_count INTEGER DEFAULT 0,
primary_cover_path TEXT,
last_scanned INTEGER,
created_at INTEGER DEFAULT (strftime('%s', 'now'))
);
CREATE TABLE IF NOT EXISTS albums (
id INTEGER PRIMARY KEY AUTOINCREMENT,
artist_id INTEGER NOT NULL,
artist_name TEXT NOT NULL,
title TEXT NOT NULL,
path TEXT NOT NULL UNIQUE,
cover_path TEXT,
track_count INTEGER DEFAULT 0,
year INTEGER,
last_scanned INTEGER,
created_at INTEGER DEFAULT (strftime('%s', 'now')),
FOREIGN KEY (artist_id) REFERENCES artists(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_artists_name ON artists(name);
CREATE INDEX IF NOT EXISTS idx_albums_artist_id ON albums(artist_id);
CREATE INDEX IF NOT EXISTS idx_albums_year ON albums(year);
CREATE INDEX IF NOT EXISTS idx_albums_artist_title ON albums(artist_name, title);
",
kind: MigrationKind::Up,
}
];
tauri::Builder::default()
.plugin(tauri_plugin_sql::Builder::new().build())
.plugin(
tauri_plugin_sql::Builder::new()
.add_migrations("sqlite:library.db", migrations)
.build()
)
.plugin(tauri_plugin_http::init())
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_store::Builder::new().build())