diff --git a/src/app/browser/database.rs b/src/app/browser/database.rs index 4de281ad..7c72b9e2 100644 --- a/src/app/browser/database.rs +++ b/src/app/browser/database.rs @@ -10,7 +10,9 @@ pub fn init(tx: &Transaction) -> Result { "CREATE TABLE IF NOT EXISTS `app_browser` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - `app_id` INTEGER NOT NULL + `app_id` INTEGER NOT NULL, + + FOREIGN KEY (`app_id`) REFERENCES `app`(`id`) )", [], ) diff --git a/src/app/browser/widget/database.rs b/src/app/browser/widget/database.rs index 55374edc..7030ed27 100644 --- a/src/app/browser/widget/database.rs +++ b/src/app/browser/widget/database.rs @@ -16,7 +16,9 @@ pub fn init(tx: &Transaction) -> Result { `app_browser_id` INTEGER NOT NULL, `default_width` INTEGER NOT NULL, `default_height` INTEGER NOT NULL, - `is_maximized` INTEGER NOT NULL + `is_maximized` INTEGER NOT NULL, + + FOREIGN KEY (`app_browser_id`) REFERENCES `app_browser`(`id`) )", [], ) diff --git a/src/app/browser/window/database.rs b/src/app/browser/window/database.rs index 8ce6f69b..d57c4589 100644 --- a/src/app/browser/window/database.rs +++ b/src/app/browser/window/database.rs @@ -10,7 +10,9 @@ pub fn init(tx: &Transaction) -> Result { "CREATE TABLE IF NOT EXISTS `app_browser_window` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - `app_browser_id` INTEGER NOT NULL + `app_browser_id` INTEGER NOT NULL, + + FOREIGN KEY (`app_browser_id`) REFERENCES `app_browser`(`id`) )", [], ) diff --git a/src/app/browser/window/tab/database.rs b/src/app/browser/window/tab/database.rs index 2750f2ad..d916ff3e 100644 --- a/src/app/browser/window/tab/database.rs +++ b/src/app/browser/window/tab/database.rs @@ -10,7 +10,9 @@ pub fn init(tx: &Transaction) -> Result { "CREATE TABLE IF NOT EXISTS `app_browser_window_tab` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - `app_browser_window_id` INTEGER NOT NULL + `app_browser_window_id` INTEGER NOT NULL, + + FOREIGN KEY (`app_browser_window_id`) REFERENCES `app_browser_window`(`id`) )", [], ) diff --git a/src/app/browser/window/tab/item/database.rs b/src/app/browser/window/tab/item/database.rs index 402896d4..a1423adc 100644 --- a/src/app/browser/window/tab/item/database.rs +++ b/src/app/browser/window/tab/item/database.rs @@ -17,7 +17,9 @@ pub fn init(tx: &Transaction) -> Result { `page_position` INTEGER NOT NULL, `is_pinned` INTEGER NOT NULL, `is_selected` INTEGER NOT NULL, - `is_attention` INTEGER NOT NULL + `is_attention` INTEGER NOT NULL, + + FOREIGN KEY (`app_browser_window_tab_id`) REFERENCES `app_browser_window_tab`(`id`) )", [], ) diff --git a/src/app/browser/window/tab/item/page/database.rs b/src/app/browser/window/tab/item/page/database.rs index 9c02a787..53a3a0b6 100644 --- a/src/app/browser/window/tab/item/page/database.rs +++ b/src/app/browser/window/tab/item/page/database.rs @@ -10,7 +10,9 @@ pub fn init(tx: &Transaction) -> Result { "CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - `app_browser_window_tab_item_id` INTEGER NOT NULL + `app_browser_window_tab_item_id` INTEGER NOT NULL, + + FOREIGN KEY (`app_browser_window_tab_item_id`) REFERENCES `app_browser_window_tab_item`(`id`) )", [], ) diff --git a/src/app/browser/window/tab/item/page/meta/database.rs b/src/app/browser/window/tab/item/page/meta/database.rs index 707f4cb9..7f5fb32e 100644 --- a/src/app/browser/window/tab/item/page/meta/database.rs +++ b/src/app/browser/window/tab/item/page/meta/database.rs @@ -12,7 +12,9 @@ pub fn init(tx: &Transaction) -> Result { ( `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `app_browser_window_tab_item_page_id` INTEGER NOT NULL, - `title` VARCHAR(1024) + `title` VARCHAR(1024), + + FOREIGN KEY (`app_browser_window_tab_item_page_id`) REFERENCES `app_browser_window_tab_item_page`(`id`) )", [], ) diff --git a/src/app/browser/window/tab/item/page/navigation/database.rs b/src/app/browser/window/tab/item/page/navigation/database.rs index 68f9e491..52cb9ae2 100644 --- a/src/app/browser/window/tab/item/page/navigation/database.rs +++ b/src/app/browser/window/tab/item/page/navigation/database.rs @@ -10,7 +10,9 @@ pub fn init(tx: &Transaction) -> Result { "CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_navigation` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - `app_browser_window_tab_item_page_id` INTEGER NOT NULL + `app_browser_window_tab_item_page_id` INTEGER NOT NULL, + + FOREIGN KEY (`app_browser_window_tab_item_page_id`) REFERENCES `app_browser_window_tab_item_page`(`id`) )", [], ) diff --git a/src/app/browser/window/tab/item/page/navigation/request/database.rs b/src/app/browser/window/tab/item/page/navigation/request/database.rs index 4b0d0e67..8e22c90d 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/database.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/database.rs @@ -10,7 +10,9 @@ pub fn init(tx: &Transaction) -> Result { "CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_navigation_request` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - `app_browser_window_tab_item_page_navigation_id` INTEGER NOT NULL + `app_browser_window_tab_item_page_navigation_id` INTEGER NOT NULL, + + FOREIGN KEY (`app_browser_window_tab_item_page_navigation_id`) REFERENCES `app_browser_window_tab_item_page_navigation`(`id`) )", [], ) diff --git a/src/app/browser/window/tab/item/page/navigation/request/widget/database.rs b/src/app/browser/window/tab/item/page/navigation/request/widget/database.rs index dbbce7de..345707d2 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/widget/database.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/widget/database.rs @@ -12,7 +12,9 @@ pub fn init(tx: &Transaction) -> Result { ( `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `app_browser_window_tab_item_page_navigation_request_id` INTEGER NOT NULL, - `text` VARCHAR(1024) + `text` VARCHAR(1024), + + FOREIGN KEY (`app_browser_window_tab_item_page_navigation_request_id`) REFERENCES `app_browser_window_tab_item_page_navigation_request`(`id`) )", [], ) diff --git a/src/app/browser/window/tab/item/widget/database.rs b/src/app/browser/window/tab/item/widget/database.rs index eab96004..1d514f0a 100644 --- a/src/app/browser/window/tab/item/widget/database.rs +++ b/src/app/browser/window/tab/item/widget/database.rs @@ -12,7 +12,9 @@ pub fn init(tx: &Transaction) -> Result { ( `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `app_browser_window_tab_item_id` INTEGER NOT NULL, - `title` VARCHAR(1024) + `title` VARCHAR(1024), + + FOREIGN KEY (`app_browser_window_tab_item_id`) REFERENCES `app_browser_window_tab_item`(`id`) )", [], ) diff --git a/src/profile/bookmark/database.rs b/src/profile/bookmark/database.rs index 33924a3f..ac52b598 100644 --- a/src/profile/bookmark/database.rs +++ b/src/profile/bookmark/database.rs @@ -82,7 +82,9 @@ pub fn init(tx: &Transaction) -> Result { `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `profile_id` INTEGER NOT NULL, `time` INTEGER NOT NULL, - `request` TEXT NOT NULL + `request` TEXT NOT NULL, + + FOREIGN KEY (`profile_id`) REFERENCES `profile`(`id`) )", [], ) diff --git a/src/profile/history/database.rs b/src/profile/history/database.rs index 232ca3ae..fede868c 100644 --- a/src/profile/history/database.rs +++ b/src/profile/history/database.rs @@ -21,7 +21,9 @@ pub fn init(tx: &Transaction) -> Result { `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `profile_id` INTEGER NOT NULL, `time` INTEGER NOT NULL, - `request` TEXT NOT NULL + `request` TEXT NOT NULL, + + FOREIGN KEY (`profile_id`) REFERENCES `profile`(`id`) )", [], ) diff --git a/src/profile/identity.rs b/src/profile/identity.rs index e3068b9c..9d28e74a 100644 --- a/src/profile/identity.rs +++ b/src/profile/identity.rs @@ -27,7 +27,7 @@ impl Identity { for auth_record in auth_records { if let Ok(gemini_records) = self.gemini.database.records() { for gemini_record in gemini_records { - if gemini_record.id == auth_record.gemini_id { + if gemini_record.id == auth_record.profile_identity_gemini_id { return Some(gemini_record.pem); } } diff --git a/src/profile/identity/gemini/auth/database.rs b/src/profile/identity/gemini/auth/database.rs index a00849cd..648a635d 100644 --- a/src/profile/identity/gemini/auth/database.rs +++ b/src/profile/identity/gemini/auth/database.rs @@ -5,10 +5,10 @@ use sqlite::{Connection, Error, Transaction}; pub struct Table { //pub id: i64, //pub profile_id: i64, - pub gemini_id: i64, + pub profile_identity_gemini_id: i64, } -/// Storage for `gemini_id` + `url` auth pairs +/// Storage for `profile_identity_gemini_id` + `url` auth pairs pub struct Database { connection: Rc>, profile_id: Rc, // multi-profile relationship @@ -41,15 +41,18 @@ pub fn init(tx: &Transaction) -> Result { tx.execute( "CREATE TABLE IF NOT EXISTS `profile_identity_gemini_auth` ( - `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - `profile_id` INTEGER NOT NULL, - `gemini_id` INTEGER NOT NULL, - `is_active` INTEGER NOT NULL, - `url` TEXT NOT NULL, + `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + `profile_id` INTEGER NOT NULL, + `profile_identity_gemini_id` INTEGER NOT NULL, + `is_active` INTEGER NOT NULL, + `url` TEXT NOT NULL, + + FOREIGN KEY (`profile_id`) REFERENCES `profile`(`id`), + FOREIGN KEY (`profile_identity_gemini_id`) REFERENCES `profile_identity_gemini`(`id`), UNIQUE ( `profile_id`, - `gemini_id`, + `profile_identity_gemini_id`, `is_active`, `url` ) @@ -62,15 +65,17 @@ pub fn select(tx: &Transaction, profile_id: i64, url: Option<&str>) -> Result Result { ( `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `profile_id` INTEGER NOT NULL, - `pem` TEXT NOT NULL + `pem` TEXT NOT NULL, + + FOREIGN KEY (`profile_id`) REFERENCES `profile`(`id`) )", [], )