Skip to content

Commit 865d9f3

Browse files
Alenarsfauveldlachaume
committed
Cleanup CardanoDbBeacon based certificate & signed entity of CardanoTransaction
Co-authored-by: Sébastien Fauvel <[email protected]> Co-authored-by: Damien Lachaume <[email protected]>
1 parent 6505bc7 commit 865d9f3

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

internal/mithril-persistence/src/database/version_checker.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ pub struct SqlMigration {
165165

166166
impl SqlMigration {
167167
/// Create a new SQL migration instance.
168-
pub fn new(version: DbVersion, alteration: &str) -> Self {
168+
pub fn new<T: Into<String>>(version: DbVersion, alteration: T) -> Self {
169169
Self {
170170
version,
171-
alterations: alteration.to_string(),
171+
alterations: alteration.into(),
172172
}
173173
}
174174
}

mithril-aggregator/src/database/migration.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Migration module
22
//!
3+
use mithril_common::entities::SignedEntityTypeDiscriminants;
34
use mithril_persistence::database::SqlMigration;
45

56
/// Get all the migrations required by this version of the software.
@@ -725,5 +726,31 @@ create index single_signature_signer_id_index on single_signature(signer_id);
725726
create index single_signature_registration_epoch_setting_id_index on single_signature(registration_epoch_setting_id);
726727
"#,
727728
),
729+
// Migration 25
730+
// Remove Certificate and SignedEntity based on CardanoTransactions since we changed their beacon
731+
SqlMigration::new(
732+
25,
733+
format!(
734+
r#"
735+
-- disable foreign keys since `certificate` and `signed_entity` are linked together
736+
pragma foreign_keys=false;
737+
738+
delete from certificate
739+
where certificate_id in (
740+
select s.certificate_id from signed_entity s
741+
where s.signed_entity_type_id = {}
742+
);
743+
744+
delete from signed_entity
745+
where signed_entity_type_id = {};
746+
747+
-- reenable foreign keys
748+
pragma foreign_key_check;
749+
pragma foreign_keys=true;
750+
"#,
751+
SignedEntityTypeDiscriminants::CardanoTransactions.index(),
752+
SignedEntityTypeDiscriminants::CardanoTransactions.index()
753+
),
754+
),
728755
]
729756
}

0 commit comments

Comments
 (0)