kitgit

tirbofish/kitgit · commit

a68c1689a44993eb1916eb90a2ef43ee3070d70a

feat: add repository pull mirroring from remotes

Verified

Thribhu K <4tkbytes@pm.me> · 2026-07-28 15:12

view full diff

diff --git a/migrations/010_repo_mirrors.sql b/migrations/010_repo_mirrors.sql
new file mode 100644
index 0000000..6d5bb5c
--- /dev/null
+++ b/migrations/010_repo_mirrors.sql
@@ -0,0 +1,15 @@
+-- Pull mirrors: fetch from a remote into the local bare repository.
+CREATE TABLE IF NOT EXISTS repo_mirrors (
+    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
+    repo_id UUID NOT NULL UNIQUE REFERENCES repositories(id) ON DELETE CASCADE,
+    remote_url TEXT NOT NULL,
+    enabled BOOLEAN NOT NULL DEFAULT TRUE,
+    last_synced_at TIMESTAMPTZ,
+    last_error TEXT,
+    created_by UUID REFERENCES users(id) ON DELETE SET NULL,
+    created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
+    updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
+    CONSTRAINT repo_mirrors_remote_url_nonempty CHECK (char_length(trim(remote_url)) > 0)
+);
+CREATE INDEX IF NOT EXISTS repo_mirrors_enabled_idx
+    ON repo_mirrors(enabled) WHERE enabled = TRUE;
diff --git a/src/db/models.rs b/src/db/models.rs
index 874e00c..236c066 100644
--- a/src/db/models.rs
+++ b/src/db/models.rs
@@ -101,6 +101,19 @@ pub struct BranchRule {
     pub created_at: DateTime<Utc>,
 }
 
+#[derive(Debug, Clone, FromRow, Serialize)]
+pub struct RepoMirror {
+    pub id: Uuid,
+    pub repo_id: Uuid,
+    pub remote_url: String,
+    pub enabled: bool,
+    pub last_synced_at: Option<DateTime<Utc>>,
+    pub last_error: Option<String>,
+    pub created_by: Option<Uuid>,
+    pub created_at: DateTime<Utc>,
+    pub updated_at: DateTime<Utc>,
+}
+
 #[derive(Debug, Clone, FromRow)]
 pub struct CommentReaction {
     pub comment_id: Uuid,
diff --git a/src/db/queries.rs b/src/db/queries.rs
index a236a11..10890a5 100644
--- a/src/db/queries.rs
+++ b/src/db/queries.rs
@@ -2349,3 +2349,82 @@ pub async fn lfs_object_size(pool: &PgPool, oid: &str) -> Result<Option<i64>> {

Large diffs are not rendered by default. Showing the first 50 of 484 lines. Show full diff