mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 00:55:28 +00:00
define foreign keys
This commit is contained in:
parent
fdc6e739b4
commit
7370815f9d
16 changed files with 59 additions and 26 deletions
|
|
@ -82,7 +82,9 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||
`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`)
|
||||
)",
|
||||
[],
|
||||
)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,9 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||
`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`)
|
||||
)",
|
||||
[],
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<RwLock<Connection>>,
|
||||
profile_id: Rc<i64>, // multi-profile relationship
|
||||
|
|
@ -41,15 +41,18 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||
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<Ve
|
|||
let mut stmt = tx.prepare(
|
||||
"SELECT `id`,
|
||||
`profile_id`,
|
||||
`gemini_id` FROM `profile_identity_gemini_auth`
|
||||
WHERE `profile_id` = ? AND `url` LIKE ?",
|
||||
`profile_identity_gemini_id`
|
||||
|
||||
FROM `profile_identity_gemini_auth`
|
||||
WHERE `profile_id` = ? AND `url` LIKE ?",
|
||||
)?;
|
||||
|
||||
let result = stmt.query_map((profile_id, url.unwrap_or("%")), |row| {
|
||||
Ok(Table {
|
||||
//id: row.get(0)?,
|
||||
//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,
|
||||
`profile_id` INTEGER NOT NULL,
|
||||
`pem` TEXT NOT NULL
|
||||
`pem` TEXT NOT NULL,
|
||||
|
||||
FOREIGN KEY (`profile_id`) REFERENCES `profile`(`id`)
|
||||
)",
|
||||
[],
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue