Skip to content

Commit e2fe5e7

Browse files
committed
Add unique constraint on 'open_message' table
1 parent b129f1a commit e2fe5e7

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

mithril-aggregator/src/database/migration.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,14 @@ insert into signed_entity (signed_entity_id,
318318
from signed_entity_old
319319
order by rowid asc;
320320
drop table signed_entity_old;
321+
"#,
322+
),
323+
// Migration 12
324+
// Alter `open_message` table
325+
SqlMigration::new(
326+
12,
327+
r#"
328+
create unique index open_message_unique_index on open_message(signed_entity_type_id, beacon);
321329
"#,
322330
),
323331
]

mithril-aggregator/src/database/provider/open_message.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -799,18 +799,25 @@ mod tests {
799799
async fn repository_clean_open_message() {
800800
let connection = get_connection().await;
801801
let repository = OpenMessageRepository::new(connection.clone());
802+
let beacon = Beacon {
803+
epoch: Epoch(1),
804+
..Beacon::default()
805+
};
802806
let _ = repository
803807
.create_open_message(
804-
Epoch(2),
805-
&SignedEntityType::CardanoImmutableFilesFull(Beacon::default()),
808+
beacon.epoch,
809+
&SignedEntityType::CardanoImmutableFilesFull(beacon.clone()),
806810
&ProtocolMessage::new(),
807811
)
808812
.await
809813
.unwrap();
810814
let _ = repository
811815
.create_open_message(
812-
Epoch(1),
813-
&SignedEntityType::CardanoImmutableFilesFull(Beacon::default()),
816+
beacon.epoch,
817+
&SignedEntityType::CardanoImmutableFilesFull(Beacon {
818+
epoch: Epoch(2),
819+
..beacon
820+
}),
814821
&ProtocolMessage::new(),
815822
)
816823
.await

0 commit comments

Comments
 (0)