mirror of
https://github.com/GothenburgBitFactory/taskchampion-sync-server.git
synced 2026-04-05 17:20:35 +00:00
Fix add_version calls when no history exists on the server (#149)
This fixes a bug in 25911b44a6 where the
check in the storage implementation was too strict (not allowing
`clients.latest_version_id == Uuid::nil()`), causing spurious failures.
Well, two bugs, one in each storage implementation.
This commit is contained in:
committed by
GitHub
parent
b57dd24d9e
commit
213be852b8
@ -272,8 +272,13 @@ impl StorageTxn for Txn {
|
|||||||
"UPDATE clients
|
"UPDATE clients
|
||||||
SET latest_version_id = $1,
|
SET latest_version_id = $1,
|
||||||
versions_since_snapshot = versions_since_snapshot + 1
|
versions_since_snapshot = versions_since_snapshot + 1
|
||||||
WHERE client_id = $2 and latest_version_id = $3",
|
WHERE client_id = $2 and (latest_version_id = $3 or latest_version_id = $4)",
|
||||||
&[&version_id, &self.client_id, &parent_version_id],
|
&[
|
||||||
|
&version_id,
|
||||||
|
&self.client_id,
|
||||||
|
&parent_version_id,
|
||||||
|
&Uuid::nil(),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.context("error updating latest_version_id")?;
|
.context("error updating latest_version_id")?;
|
||||||
@ -689,4 +694,22 @@ mod test {
|
|||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
/// When an add_version call specifies a `parent_version_id` that does not exist in the
|
||||||
|
/// DB, but no other versions exist, the call succeeds.
|
||||||
|
async fn test_add_version_no_history() -> anyhow::Result<()> {
|
||||||
|
with_db(async |connection_string, db_client| {
|
||||||
|
let storage = PostgresStorage::new(connection_string).await?;
|
||||||
|
let client_id = make_client(&db_client).await?;
|
||||||
|
|
||||||
|
let mut txn = storage.txn(client_id).await?;
|
||||||
|
let version_id = Uuid::new_v4();
|
||||||
|
let parent_version_id = Uuid::new_v4();
|
||||||
|
txn.add_version(version_id, parent_version_id, b"v1".to_vec())
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -276,11 +276,12 @@ impl StorageTxn for Txn {
|
|||||||
SET
|
SET
|
||||||
latest_version_id = ?,
|
latest_version_id = ?,
|
||||||
versions_since_snapshot = versions_since_snapshot + 1
|
versions_since_snapshot = versions_since_snapshot + 1
|
||||||
WHERE client_id = ? and latest_version_id = ?",
|
WHERE client_id = ? and (latest_version_id = ? or latest_version_id = ?)",
|
||||||
params![
|
params![
|
||||||
StoredUuid(version_id),
|
StoredUuid(version_id),
|
||||||
StoredUuid(self.client_id),
|
StoredUuid(self.client_id),
|
||||||
StoredUuid(parent_version_id)
|
StoredUuid(parent_version_id),
|
||||||
|
StoredUuid(Uuid::nil())
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.context("Error updating client for new version")?;
|
.context("Error updating client for new version")?;
|
||||||
@ -489,4 +490,21 @@ mod test {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
/// When an add_version call specifies a `parent_version_id` that does not exist in the
|
||||||
|
/// DB, but no other versions exist, the call succeeds.
|
||||||
|
async fn test_add_version_no_history() -> anyhow::Result<()> {
|
||||||
|
let tmp_dir = TempDir::new()?;
|
||||||
|
let storage = SqliteStorage::new(tmp_dir.path())?;
|
||||||
|
let client_id = Uuid::new_v4();
|
||||||
|
let mut txn = storage.txn(client_id).await?;
|
||||||
|
txn.new_client(Uuid::nil()).await?;
|
||||||
|
|
||||||
|
let version_id = Uuid::new_v4();
|
||||||
|
let parent_version_id = Uuid::new_v4();
|
||||||
|
txn.add_version(version_id, parent_version_id, b"v1".to_vec())
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user