mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
define foreign keys
This commit is contained in:
parent
fdc6e739b4
commit
7370815f9d
@ -10,7 +10,9 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||||||
"CREATE TABLE IF NOT EXISTS `app_browser`
|
"CREATE TABLE IF NOT EXISTS `app_browser`
|
||||||
(
|
(
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
`app_id` INTEGER NOT NULL
|
`app_id` INTEGER NOT NULL,
|
||||||
|
|
||||||
|
FOREIGN KEY (`app_id`) REFERENCES `app`(`id`)
|
||||||
)",
|
)",
|
||||||
[],
|
[],
|
||||||
)
|
)
|
||||||
|
@ -16,7 +16,9 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||||||
`app_browser_id` INTEGER NOT NULL,
|
`app_browser_id` INTEGER NOT NULL,
|
||||||
`default_width` INTEGER NOT NULL,
|
`default_width` INTEGER NOT NULL,
|
||||||
`default_height` 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`)
|
||||||
)",
|
)",
|
||||||
[],
|
[],
|
||||||
)
|
)
|
||||||
|
@ -10,7 +10,9 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||||||
"CREATE TABLE IF NOT EXISTS `app_browser_window`
|
"CREATE TABLE IF NOT EXISTS `app_browser_window`
|
||||||
(
|
(
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
`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`)
|
||||||
)",
|
)",
|
||||||
[],
|
[],
|
||||||
)
|
)
|
||||||
|
@ -10,7 +10,9 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||||||
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab`
|
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab`
|
||||||
(
|
(
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
`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`)
|
||||||
)",
|
)",
|
||||||
[],
|
[],
|
||||||
)
|
)
|
||||||
|
@ -17,7 +17,9 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||||||
`page_position` INTEGER NOT NULL,
|
`page_position` INTEGER NOT NULL,
|
||||||
`is_pinned` INTEGER NOT NULL,
|
`is_pinned` INTEGER NOT NULL,
|
||||||
`is_selected` 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`)
|
||||||
)",
|
)",
|
||||||
[],
|
[],
|
||||||
)
|
)
|
||||||
|
@ -10,7 +10,9 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||||||
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page`
|
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page`
|
||||||
(
|
(
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
`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`)
|
||||||
)",
|
)",
|
||||||
[],
|
[],
|
||||||
)
|
)
|
||||||
|
@ -12,7 +12,9 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||||||
(
|
(
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
`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,
|
||||||
`title` VARCHAR(1024)
|
`title` VARCHAR(1024),
|
||||||
|
|
||||||
|
FOREIGN KEY (`app_browser_window_tab_item_page_id`) REFERENCES `app_browser_window_tab_item_page`(`id`)
|
||||||
)",
|
)",
|
||||||
[],
|
[],
|
||||||
)
|
)
|
||||||
|
@ -10,7 +10,9 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||||||
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_navigation`
|
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_navigation`
|
||||||
(
|
(
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
`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`)
|
||||||
)",
|
)",
|
||||||
[],
|
[],
|
||||||
)
|
)
|
||||||
|
@ -10,7 +10,9 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||||||
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_navigation_request`
|
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_navigation_request`
|
||||||
(
|
(
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
`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`)
|
||||||
)",
|
)",
|
||||||
[],
|
[],
|
||||||
)
|
)
|
||||||
|
@ -12,7 +12,9 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||||||
(
|
(
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
`app_browser_window_tab_item_page_navigation_request_id` INTEGER 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`)
|
||||||
)",
|
)",
|
||||||
[],
|
[],
|
||||||
)
|
)
|
||||||
|
@ -12,7 +12,9 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||||||
(
|
(
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
`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,
|
||||||
`title` VARCHAR(1024)
|
`title` VARCHAR(1024),
|
||||||
|
|
||||||
|
FOREIGN KEY (`app_browser_window_tab_item_id`) REFERENCES `app_browser_window_tab_item`(`id`)
|
||||||
)",
|
)",
|
||||||
[],
|
[],
|
||||||
)
|
)
|
||||||
|
@ -82,7 +82,9 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
`profile_id` INTEGER NOT NULL,
|
`profile_id` INTEGER NOT NULL,
|
||||||
`time` INTEGER NOT NULL,
|
`time` INTEGER NOT NULL,
|
||||||
`request` TEXT NOT NULL
|
`request` TEXT NOT NULL,
|
||||||
|
|
||||||
|
FOREIGN KEY (`profile_id`) REFERENCES `profile`(`id`)
|
||||||
)",
|
)",
|
||||||
[],
|
[],
|
||||||
)
|
)
|
||||||
|
@ -21,7 +21,9 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
`profile_id` INTEGER NOT NULL,
|
`profile_id` INTEGER NOT NULL,
|
||||||
`time` INTEGER NOT NULL,
|
`time` INTEGER NOT NULL,
|
||||||
`request` TEXT NOT NULL
|
`request` TEXT NOT NULL,
|
||||||
|
|
||||||
|
FOREIGN KEY (`profile_id`) REFERENCES `profile`(`id`)
|
||||||
)",
|
)",
|
||||||
[],
|
[],
|
||||||
)
|
)
|
||||||
|
@ -27,7 +27,7 @@ impl Identity {
|
|||||||
for auth_record in auth_records {
|
for auth_record in auth_records {
|
||||||
if let Ok(gemini_records) = self.gemini.database.records() {
|
if let Ok(gemini_records) = self.gemini.database.records() {
|
||||||
for gemini_record in gemini_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);
|
return Some(gemini_record.pem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,10 @@ use sqlite::{Connection, Error, Transaction};
|
|||||||
pub struct Table {
|
pub struct Table {
|
||||||
//pub id: i64,
|
//pub id: i64,
|
||||||
//pub profile_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 {
|
pub struct Database {
|
||||||
connection: Rc<RwLock<Connection>>,
|
connection: Rc<RwLock<Connection>>,
|
||||||
profile_id: Rc<i64>, // multi-profile relationship
|
profile_id: Rc<i64>, // multi-profile relationship
|
||||||
@ -41,15 +41,18 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||||||
tx.execute(
|
tx.execute(
|
||||||
"CREATE TABLE IF NOT EXISTS `profile_identity_gemini_auth`
|
"CREATE TABLE IF NOT EXISTS `profile_identity_gemini_auth`
|
||||||
(
|
(
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
`profile_id` INTEGER NOT NULL,
|
`profile_id` INTEGER NOT NULL,
|
||||||
`gemini_id` INTEGER NOT NULL,
|
`profile_identity_gemini_id` INTEGER NOT NULL,
|
||||||
`is_active` INTEGER NOT NULL,
|
`is_active` INTEGER NOT NULL,
|
||||||
`url` TEXT 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 (
|
UNIQUE (
|
||||||
`profile_id`,
|
`profile_id`,
|
||||||
`gemini_id`,
|
`profile_identity_gemini_id`,
|
||||||
`is_active`,
|
`is_active`,
|
||||||
`url`
|
`url`
|
||||||
)
|
)
|
||||||
@ -62,15 +65,17 @@ pub fn select(tx: &Transaction, profile_id: i64, url: Option<&str>) -> Result<Ve
|
|||||||
let mut stmt = tx.prepare(
|
let mut stmt = tx.prepare(
|
||||||
"SELECT `id`,
|
"SELECT `id`,
|
||||||
`profile_id`,
|
`profile_id`,
|
||||||
`gemini_id` FROM `profile_identity_gemini_auth`
|
`profile_identity_gemini_id`
|
||||||
WHERE `profile_id` = ? AND `url` LIKE ?",
|
|
||||||
|
FROM `profile_identity_gemini_auth`
|
||||||
|
WHERE `profile_id` = ? AND `url` LIKE ?",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let result = stmt.query_map((profile_id, url.unwrap_or("%")), |row| {
|
let result = stmt.query_map((profile_id, url.unwrap_or("%")), |row| {
|
||||||
Ok(Table {
|
Ok(Table {
|
||||||
//id: row.get(0)?,
|
//id: row.get(0)?,
|
||||||
//profile_id: row.get(1)?,
|
//profile_id: row.get(1)?,
|
||||||
gemini_id: row.get(2)?,
|
profile_identity_gemini_id: row.get(2)?,
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
@ -40,7 +40,9 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||||||
(
|
(
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
`profile_id` INTEGER NOT NULL,
|
`profile_id` INTEGER NOT NULL,
|
||||||
`pem` TEXT NOT NULL
|
`pem` TEXT NOT NULL,
|
||||||
|
|
||||||
|
FOREIGN KEY (`profile_id`) REFERENCES `profile`(`id`)
|
||||||
)",
|
)",
|
||||||
[],
|
[],
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user