Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reintroduce uniqueness check #764

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading