feat(db): create new URL table and update the existing table to include a foreign key to the URLs table

This commit is contained in:
ryan 2025-02-11 23:35:49 +03:00
parent 443c7a7e0c
commit ce1e93fc49

View file

@ -25,16 +25,26 @@ mod db_impl {
// Create the database schema // Create the database schema
pub async fn create_schema(&self) -> Result<(), Error> { pub async fn create_schema(&self) -> Result<(), Error> {
let conn = self.conn.lock().await; let conn = self.conn.lock().await;
conn.execute_batch(
"CREATE TABLE IF NOT EXISTS urls (
id INTEGER PRIMARY KEY,
url TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);",
)?;
logging::log!("URLs table created or verified");
conn.execute_batch( conn.execute_batch(
"CREATE TABLE IF NOT EXISTS items ( "CREATE TABLE IF NOT EXISTS items (
id TEXT PRIMARY KEY, id TEXT PRIMARY KEY,
name TEXT NOT NULL, name TEXT NOT NULL,
description TEXT, description TEXT,
wikidata_id TEXT, wikidata_id TEXT,
custom_properties TEXT custom_properties TEXT,
url_id INTEGER,
FOREIGN KEY (url_id) REFERENCES urls (id)
);", );",
)?; )?;
logging::log!("Database schema created or verified"); logging::log!("Items table updated with foreign key to URLs table");
Ok(()) Ok(())
} }