Add "tracked" column to table "commits"
This commit is contained in:
parent
b56d0df142
commit
1f66fe0299
3 changed files with 36 additions and 3 deletions
12
.sqlx/query-6398e5b1dce1142d3460f9d067588bcb42b0be5278ce7524280a4786c8b41786.json
generated
Normal file
12
.sqlx/query-6398e5b1dce1142d3460f9d067588bcb42b0be5278ce7524280a4786c8b41786.json
generated
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"db_name": "SQLite",
|
||||||
|
"query": "\nWITH RECURSIVE reachable(hash) AS (\n SELECT hash FROM tracked_refs\n UNION\n SELECT parent FROM commit_links\n JOIN reachable ON hash = child\n)\n\nUPDATE commits\nSET tracked = (hash IN reachable)\n",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 0
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "6398e5b1dce1142d3460f9d067588bcb42b0be5278ce7524280a4786c8b41786"
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
CREATE TABLE commits (
|
CREATE TABLE commits (
|
||||||
hash TEXT NOT NULL PRIMARY KEY,
|
hash TEXT NOT NULL PRIMARY KEY,
|
||||||
new INT NOT NULL DEFAULT 1
|
new INT NOT NULL DEFAULT 1,
|
||||||
|
tracked INT NOT NULL DEFAULT 0
|
||||||
) STRICT;
|
) STRICT;
|
||||||
|
|
||||||
CREATE TABLE commit_links (
|
CREATE TABLE commit_links (
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,25 @@ async fn update_tracked_refs(conn: &mut SqliteConnection, repo: &Repository) ->
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn update_commit_tracked_status(conn: &mut SqliteConnection) -> anyhow::Result<()> {
|
||||||
|
sqlx::query!(
|
||||||
|
"
|
||||||
|
WITH RECURSIVE reachable(hash) AS (
|
||||||
|
SELECT hash FROM tracked_refs
|
||||||
|
UNION
|
||||||
|
SELECT parent FROM commit_links
|
||||||
|
JOIN reachable ON hash = child
|
||||||
|
)
|
||||||
|
|
||||||
|
UPDATE commits
|
||||||
|
SET tracked = (hash IN reachable)
|
||||||
|
"
|
||||||
|
)
|
||||||
|
.execute(conn)
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn update(db: &SqlitePool, repo: &Repository) -> anyhow::Result<()> {
|
pub async fn update(db: &SqlitePool, repo: &Repository) -> anyhow::Result<()> {
|
||||||
debug!("Updating repo");
|
debug!("Updating repo");
|
||||||
let mut tx = db.begin().await?;
|
let mut tx = db.begin().await?;
|
||||||
|
|
@ -136,7 +155,6 @@ pub async fn update(db: &SqlitePool, repo: &Repository) -> anyhow::Result<()> {
|
||||||
debug!("Loaded {} commits from the db", old.len());
|
debug!("Loaded {} commits from the db", old.len());
|
||||||
|
|
||||||
let repo_is_new = old.is_empty();
|
let repo_is_new = old.is_empty();
|
||||||
|
|
||||||
if repo_is_new {
|
if repo_is_new {
|
||||||
info!("Initializing new repo");
|
info!("Initializing new repo");
|
||||||
}
|
}
|
||||||
|
|
@ -164,6 +182,8 @@ pub async fn update(db: &SqlitePool, repo: &Repository) -> anyhow::Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
update_tracked_refs(conn, repo).await?;
|
update_tracked_refs(conn, repo).await?;
|
||||||
|
update_commit_tracked_status(conn).await?;
|
||||||
|
debug!("Updated tracked refs");
|
||||||
|
|
||||||
tx.commit().await?;
|
tx.commit().await?;
|
||||||
if repo_is_new {
|
if repo_is_new {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue