Skip to content

Commit

Permalink
Reintroduce uniqueness check (#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop authored Aug 5, 2024
1 parent 0669f38 commit 2c16474
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions schemas/database/014_reintroduce_root_uniqueness.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Same as migration 011_drop_root_uniqueness.sql

DROP INDEX identities_root_key;

CREATE INDEX identities_root ON identities (root);
3 changes: 3 additions & 0 deletions schemas/database/014_reintroduce_root_uniqueness.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DROP INDEX identities_root;

CREATE UNIQUE INDEX identities_root_key ON identities (root);
9 changes: 6 additions & 3 deletions src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ mod test {
}

#[tokio::test]
async fn can_insert_same_root_multiple_times() -> anyhow::Result<()> {
async fn can_not_insert_same_root_multiple_times() -> anyhow::Result<()> {
let docker = Cli::default();
let (db, _db_container) = setup_db(&docker).await?;
let identities = mock_identities(2);
Expand All @@ -1185,8 +1185,11 @@ mod test {
db.insert_pending_identity(0, &identities[0], &roots[0])
.await?;

db.insert_pending_identity(1, &identities[1], &roots[0])
.await?;
let res = db
.insert_pending_identity(1, &identities[1], &roots[0])
.await;

assert!(res.is_err(), "Inserting duplicate root should fail");

let root_state = db
.get_root_state(&roots[0])
Expand Down

0 comments on commit 2c16474

Please sign in to comment.