Compare commits

..

No commits in common. "a35d4d557d81ca12b3962eade5820a624bd7c863" and "a8d8e9a13166c47e1e87d13e42e362ff60d49f5e" have entirely different histories.

3 changed files with 17 additions and 39 deletions

View file

@ -84,19 +84,8 @@ pub fn ItemsList(
// Signal to store the fetched property labels // Signal to store the fetched property labels
let (property_labels, set_property_labels) = create_signal(HashMap::<String, String>::new()); let (property_labels, set_property_labels) = create_signal(HashMap::<String, String>::new());
#[cfg(feature = "ssr")]
fn get_current_url() -> String { fn get_current_url() -> String {
use leptos::use_context; window()
use actix_web::HttpRequest;
use_context::<HttpRequest>()
.map(|req| req.uri().to_string())
.unwrap_or_default()
}
#[cfg(not(feature = "ssr"))]
fn get_current_url() -> String {
web_sys::window()
.and_then(|win| win.location().href().ok()) .and_then(|win| win.location().href().ok())
.unwrap_or_else(|| "".to_string()) .unwrap_or_else(|| "".to_string())
} }

View file

@ -36,22 +36,17 @@ mod db_impl {
name TEXT NOT NULL UNIQUE, name TEXT NOT NULL UNIQUE,
global_usage_count INTEGER DEFAULT 0 global_usage_count INTEGER DEFAULT 0
);" );"
).map_err(|e| { )?;
eprintln!("Failed creating properties table: {}", e);
e
})?;
// 2. URLs table // 2. URLs table
conn.execute_batch( conn.execute_batch(
"CREATE TABLE IF NOT EXISTS urls ( "CREATE TABLE IF NOT EXISTS urls (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
url TEXT NOT NULL UNIQUE, url TEXT NOT NULL UNIQUE, // Enforce unique URLs
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);", );",
).map_err(|e| { )?;
eprintln!("Failed creating urls table: {}", e); logging::log!("URLs table created or verified");
e
})?;
// 3. Items table // 3. Items table
conn.execute_batch( conn.execute_batch(
@ -63,10 +58,8 @@ mod db_impl {
wikidata_id TEXT, wikidata_id TEXT,
FOREIGN KEY (url_id) REFERENCES urls(id) ON DELETE CASCADE FOREIGN KEY (url_id) REFERENCES urls(id) ON DELETE CASCADE
);", );",
).map_err(|e| { )?;
eprintln!("Failed creating items table: {}", e); logging::log!("Items table updated with foreign key to URLs table");
e
})?;
// 4. Junction table for custom properties // 4. Junction table for custom properties
conn.execute_batch( conn.execute_batch(
@ -78,10 +71,7 @@ mod db_impl {
FOREIGN KEY (item_id) REFERENCES items(id) ON DELETE CASCADE, FOREIGN KEY (item_id) REFERENCES items(id) ON DELETE CASCADE,
FOREIGN KEY (property_id) REFERENCES properties(id) ON DELETE CASCADE FOREIGN KEY (property_id) REFERENCES properties(id) ON DELETE CASCADE
);" );"
).map_err(|e| { )?;
eprintln!("Failed creating item_properties table: {}", e);
e
})?;
Ok(()) Ok(())
} }

View file

@ -18,16 +18,15 @@ async fn main() -> std::io::Result<()> {
use std::sync::Arc; use std::sync::Arc;
use tokio::sync::Mutex; use tokio::sync::Mutex;
// Initialize the database
let db = Database::new("compareware.db").unwrap();
db.create_schema().await.unwrap(); // Ensure the schema is created
let db = Arc::new(Mutex::new(db)); // Wrap the database in an Arc<Mutex<T>> for shared state
println!("Schema created successfully!");
// Load configuration // Load configuration
let conf = get_configuration(None).await.unwrap(); let conf = get_configuration(None).await.unwrap();
let addr = conf.leptos_options.site_addr; let addr = conf.leptos_options.site_addr;
// Initialize the database
let db = Database::new("compareware.db").unwrap();
db.create_schema().await.unwrap(); // Ensure the schema is created
let db = Arc::new(Mutex::new(db)); // Wrap the database in an Arc<Mutex<T>> for shared state
// Generate the list of routes in your Leptos App // Generate the list of routes in your Leptos App
let routes = generate_route_list(App); let routes = generate_route_list(App);