summaryrefslogtreecommitdiff
path: root/src/db.rs
diff options
context:
space:
mode:
authorJesper Jensen <jesper@jnsn.dev>2026-02-09 17:37:56 +0100
committerJesper Jensen <jesper@jnsn.dev>2026-02-09 17:37:56 +0100
commitf5dd11f8b3eb9b3285fa8c58d611e2dd46d35fda (patch)
tree736554dc7065ed9a940235262fb6518206d5de6f /src/db.rs
parent5d5baab71c72d738b3f6e841ccb0319d708e0b21 (diff)
Remove timestamp from tags
These were never needed
Diffstat (limited to 'src/db.rs')
-rw-r--r--src/db.rs54
1 files changed, 29 insertions, 25 deletions
diff --git a/src/db.rs b/src/db.rs
index 469a279..26ea78a 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -17,10 +17,10 @@ pub trait Db {
fn get_expired_images(&self, now: &DateTime<Utc>) -> Vec<Image>;
fn get_tags_sorted(&self, image_id: i64) -> Vec<String>;
fn delete_tag(&self, image_id: i64, tag: &str);
- fn insert_tag(&self, image_id: i64, tag: &str, fetched_at: &DateTime<Utc>);
+ fn insert_tag(&self, image_id: i64, tag: &str);
fn set_expires_at(&self, image_id: i64, expires_at: &DateTime<Utc>);
fn get_tag_digest(&self, image_id: i64, tag: &str) -> Option<String>;
- fn update_tag_digest(&self, image_id: i64, tag: &str, digest: &str, fetched_at: &DateTime<Utc>);
+ fn update_tag_digest(&self, image_id: i64, tag: &str, digest: &str);
}
pub struct SqliteDb {
@@ -113,6 +113,11 @@ impl SqliteDb {
conn.execute("INSERT INTO migrations(id) VALUES (?1)", (7, )).unwrap();
}
+ if newest_migration < 8 {
+ conn.execute("ALTER TABLE tags DROP COLUMN fetched_at", ()).unwrap();
+ conn.execute("INSERT INTO migrations(id) VALUES (?1)", (8, )).unwrap();
+ }
+
return SqliteDb { conn };
}
}
@@ -174,10 +179,10 @@ impl Db for SqliteDb {
(image_id, tag)).unwrap();
}
- fn insert_tag(&self, image_id: i64, tag: &str, fetched_at: &DateTime<Utc>) {
+ fn insert_tag(&self, image_id: i64, tag: &str) {
let _timer = crate::metrics::get().db_query_duration.start_timer();
- self.conn.execute("INSERT INTO tags(image_id, tag, fetched_at) VALUES (?1, ?2, ?3)",
- (image_id, tag, fetched_at)).unwrap();
+ self.conn.execute("INSERT INTO tags(image_id, tag) VALUES (?1, ?2)",
+ (image_id, tag)).unwrap();
}
fn set_expires_at(&self, image_id: i64, expires_at: &DateTime<Utc>) {
@@ -192,10 +197,10 @@ impl Db for SqliteDb {
", (image_id, tag), |row| row.get::<_, String>(0)).optional().unwrap();
}
- fn update_tag_digest(&self, image_id: i64, tag: &str, digest: &str, fetched_at: &DateTime<Utc>) {
+ fn update_tag_digest(&self, image_id: i64, tag: &str, digest: &str) {
let _timer = crate::metrics::get().db_query_duration.start_timer();
- self.conn.execute("UPDATE tags SET digest = ?1, fetched_at = ?2 WHERE image_id = ?3 AND tag = ?4",
- (digest, fetched_at, image_id, tag)).unwrap();
+ self.conn.execute("UPDATE tags SET digest = ?1 WHERE image_id = ?2 AND tag = ?3",
+ (digest, image_id, tag)).unwrap();
}
}
@@ -203,7 +208,7 @@ impl Db for SqliteDb {
pub struct StubDb {
next_id: std::cell::RefCell<i64>,
images: std::cell::RefCell<Vec<Image>>,
- tags: std::cell::RefCell<Vec<(i64, String, Option<String>, DateTime<Utc>)>>,
+ tags: std::cell::RefCell<Vec<(i64, String, Option<String>)>>,
}
#[cfg(test)]
@@ -262,7 +267,7 @@ impl Db for StubDb {
fn get_tags_sorted(&self, image_id: i64) -> Vec<String> {
let mut result = vec![];
- for (id, tag, _, _) in self.tags.borrow().iter() {
+ for (id, tag, _) in self.tags.borrow().iter() {
if *id == image_id {
result.push(tag.clone());
}
@@ -272,11 +277,11 @@ impl Db for StubDb {
}
fn delete_tag(&self, image_id: i64, tag: &str) {
- self.tags.borrow_mut().retain(|(id, t, _, _)| !(*id == image_id && t == tag));
+ self.tags.borrow_mut().retain(|(id, t, _)| !(*id == image_id && t == tag));
}
- fn insert_tag(&self, image_id: i64, tag: &str, fetched_at: &DateTime<Utc>) {
- self.tags.borrow_mut().push((image_id, tag.to_string(), None, fetched_at.clone()));
+ fn insert_tag(&self, image_id: i64, tag: &str) {
+ self.tags.borrow_mut().push((image_id, tag.to_string(), None));
}
fn set_expires_at(&self, image_id: i64, expires_at: &DateTime<Utc>) {
@@ -289,7 +294,7 @@ impl Db for StubDb {
}
fn get_tag_digest(&self, image_id: i64, tag: &str) -> Option<String> {
- for (id, t, digest, _) in self.tags.borrow().iter() {
+ for (id, t, digest) in self.tags.borrow().iter() {
if *id == image_id && t == tag {
return digest.clone();
}
@@ -297,11 +302,10 @@ impl Db for StubDb {
return None;
}
- fn update_tag_digest(&self, image_id: i64, tag: &str, digest: &str, fetched_at: &DateTime<Utc>) {
- for (id, t, d, fa) in self.tags.borrow_mut().iter_mut() {
+ fn update_tag_digest(&self, image_id: i64, tag: &str, digest: &str) {
+ for (id, t, d) in self.tags.borrow_mut().iter_mut() {
if *id == image_id && t == tag {
*d = Some(digest.to_string());
- *fa = fetched_at.clone();
return;
}
}
@@ -346,9 +350,9 @@ mod tests {
let now = Utc.with_ymd_and_hms(2000, 1, 1, 0, 0, 0).unwrap();
let mut img = Image { id: 0, registry: "docker.io".into(), image: "nginx".into(), expires_at: now };
db.insert_image(&mut img);
- db.insert_tag(img.id, "2.0", &now);
- db.insert_tag(img.id, "1.0", &now);
- db.insert_tag(img.id, "latest", &now);
+ db.insert_tag(img.id, "2.0");
+ db.insert_tag(img.id, "1.0");
+ db.insert_tag(img.id, "latest");
assert_eq!(db.get_tags_sorted(img.id), vec!["1.0", "2.0", "latest"]);
}
@@ -356,8 +360,8 @@ mod tests {
let now = Utc.with_ymd_and_hms(2000, 1, 1, 0, 0, 0).unwrap();
let mut img = Image { id: 0, registry: "docker.io".into(), image: "nginx".into(), expires_at: now };
db.insert_image(&mut img);
- db.insert_tag(img.id, "1.0", &now);
- db.insert_tag(img.id, "2.0", &now);
+ db.insert_tag(img.id, "1.0");
+ db.insert_tag(img.id, "2.0");
db.delete_tag(img.id, "1.0");
assert_eq!(db.get_tags_sorted(img.id), vec!["2.0"]);
}
@@ -375,7 +379,7 @@ mod tests {
let now = Utc.with_ymd_and_hms(2000, 1, 1, 0, 0, 0).unwrap();
let mut img = Image { id: 0, registry: "docker.io".into(), image: "nginx".into(), expires_at: now };
db.insert_image(&mut img);
- db.insert_tag(img.id, "1.0", &now);
+ db.insert_tag(img.id, "1.0");
assert_eq!(db.get_tag_digest(img.id, "1.0"), None);
}
@@ -383,8 +387,8 @@ mod tests {
let now = Utc.with_ymd_and_hms(2000, 1, 1, 0, 0, 0).unwrap();
let mut img = Image { id: 0, registry: "docker.io".into(), image: "nginx".into(), expires_at: now };
db.insert_image(&mut img);
- db.insert_tag(img.id, "1.0", &now);
- db.update_tag_digest(img.id, "1.0", "sha256:abc", &now);
+ db.insert_tag(img.id, "1.0");
+ db.update_tag_digest(img.id, "1.0", "sha256:abc");
assert_eq!(db.get_tag_digest(img.id, "1.0"), Some("sha256:abc".to_string()));
}