diff --git a/schemas/database/014_reintroduce_root_uniqueness.down.sql b/schemas/database/014_reintroduce_root_uniqueness.down.sql new file mode 100644 index 00000000..aa59048e --- /dev/null +++ b/schemas/database/014_reintroduce_root_uniqueness.down.sql @@ -0,0 +1,5 @@ +-- Same as migration 011_drop_root_uniqueness.sql + +DROP INDEX identities_root_key; + +CREATE INDEX identities_root ON identities (root); diff --git a/schemas/database/014_reintroduce_root_uniqueness.up.sql b/schemas/database/014_reintroduce_root_uniqueness.up.sql new file mode 100644 index 00000000..9364a87d --- /dev/null +++ b/schemas/database/014_reintroduce_root_uniqueness.up.sql @@ -0,0 +1,3 @@ +DROP INDEX identities_root; + +CREATE UNIQUE INDEX identities_root_key ON identities (root); diff --git a/src/database/mod.rs b/src/database/mod.rs index 92de9212..61ee8cfa 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -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); @@ -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])