From ce1e93fc492ce09620a984e96befe14806519e22 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 11 Feb 2025 23:35:49 +0300 Subject: [PATCH] feat(db): create new URL table and update the existing table to include a foreign key to the URLs table --- src/db.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/db.rs b/src/db.rs index 16fe958..bd13d6d 100644 --- a/src/db.rs +++ b/src/db.rs @@ -25,16 +25,26 @@ mod db_impl { // Create the database schema pub async fn create_schema(&self) -> Result<(), Error> { 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( "CREATE TABLE IF NOT EXISTS items ( id TEXT PRIMARY KEY, name TEXT NOT NULL, description 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(()) }