fix(reco): fix migration for existing users without genre_id column
Remove genre_id from base schema and let migration add it. This ensures existing databases don't fail when trying to create index on non-existent column during initial schema execution.
This commit is contained in:
1 parent
8428fafaa5
commit
733a12d702
1 file changed
+2
-3
@@ -39,6 +39,7 @@ impl RecoStoreDb {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn init(&self) -> Result<(), String> {
|
fn init(&self) -> Result<(), String> {
|
||||||
|
// Base schema - does NOT include genre_id (added via migration)
|
||||||
self.conn
|
self.conn
|
||||||
.execute_batch(
|
.execute_batch(
|
||||||
r#"
|
r#"
|
||||||
@@ -50,7 +51,6 @@ impl RecoStoreDb {
|
|||||||
album_id TEXT,
|
album_id TEXT,
|
||||||
artist_id INTEGER,
|
artist_id INTEGER,
|
||||||
playlist_id INTEGER,
|
playlist_id INTEGER,
|
||||||
genre_id INTEGER,
|
|
||||||
created_at INTEGER NOT NULL
|
created_at INTEGER NOT NULL
|
||||||
);
|
);
|
||||||
CREATE INDEX IF NOT EXISTS idx_reco_events_type ON reco_events(event_type);
|
CREATE INDEX IF NOT EXISTS idx_reco_events_type ON reco_events(event_type);
|
||||||
@@ -58,7 +58,6 @@ impl RecoStoreDb {
|
|||||||
CREATE INDEX IF NOT EXISTS idx_reco_events_album ON reco_events(album_id);
|
CREATE INDEX IF NOT EXISTS idx_reco_events_album ON reco_events(album_id);
|
||||||
CREATE INDEX IF NOT EXISTS idx_reco_events_artist ON reco_events(artist_id);
|
CREATE INDEX IF NOT EXISTS idx_reco_events_artist ON reco_events(artist_id);
|
||||||
CREATE INDEX IF NOT EXISTS idx_reco_events_created ON reco_events(created_at);
|
CREATE INDEX IF NOT EXISTS idx_reco_events_created ON reco_events(created_at);
|
||||||
CREATE INDEX IF NOT EXISTS idx_reco_events_genre ON reco_events(genre_id);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS reco_scores (
|
CREATE TABLE IF NOT EXISTS reco_scores (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
@@ -79,7 +78,7 @@ impl RecoStoreDb {
|
|||||||
)
|
)
|
||||||
.map_err(|e| format!("Failed to initialize reco database: {}", e))?;
|
.map_err(|e| format!("Failed to initialize reco database: {}", e))?;
|
||||||
|
|
||||||
// Migration: Add genre_id column if it doesn't exist
|
// Migrations - run after base schema
|
||||||
self.migrate_add_genre_id()?;
|
self.migrate_add_genre_id()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in new issue
Block a user