Skip to content

Commit f4cafd6

Browse files
authored
Merge pull request #1626 from input-output-hk/djo/1583/refactor_aggregator_db
Refactor Aggregator & Signer database structure
2 parents f700c46 + 0b50f2a commit f4cafd6

File tree

102 files changed

+7299
-7869
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+7299
-7869
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/mithril-persistence/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-persistence"
3-
version = "0.1.5"
3+
version = "0.1.6"
44
description = "Common types, interfaces, and utilities to persist data for Mithril nodes."
55
authors = { workspace = true }
66
edition = { workspace = true }

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

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'conn> DatabaseVersionChecker<'conn> {
5151
}
5252

5353
/// Apply migrations
54-
pub async fn apply(&self) -> StdResult<()> {
54+
pub fn apply(&self) -> StdResult<()> {
5555
debug!(&self.logger, "check database version",);
5656
let provider = DatabaseVersionProvider::new(self.connection);
5757
provider
@@ -179,7 +179,7 @@ mod tests {
179179

180180
use super::*;
181181

182-
async fn check_database_version(connection: &SqliteConnection, db_version: DbVersion) {
182+
fn check_database_version(connection: &SqliteConnection, db_version: DbVersion) {
183183
let provider = DatabaseVersionProvider::new(connection);
184184
let version = provider
185185
.get_application_version(&ApplicationNodeType::Aggregator)
@@ -199,7 +199,7 @@ mod tests {
199199
Ok((filepath, connection))
200200
}
201201

202-
async fn get_table_whatever_column_count(connection: &SqliteConnection) -> i64 {
202+
fn get_table_whatever_column_count(connection: &SqliteConnection) -> i64 {
203203
let sql = "select count(*) as column_count from pragma_table_info('whatever');";
204204
let column_count = connection
205205
.prepare(sql)
@@ -213,8 +213,8 @@ mod tests {
213213
column_count
214214
}
215215

216-
#[tokio::test]
217-
async fn test_upgrade_with_migration() {
216+
#[test]
217+
fn test_upgrade_with_migration() {
218218
let (_filepath, connection) =
219219
create_sqlite_file("test_upgrade_with_migration.sqlite3").unwrap();
220220
let mut db_checker = DatabaseVersionChecker::new(
@@ -223,35 +223,35 @@ mod tests {
223223
&connection,
224224
);
225225

226-
db_checker.apply().await.unwrap();
227-
assert_eq!(0, get_table_whatever_column_count(&connection).await);
226+
db_checker.apply().unwrap();
227+
assert_eq!(0, get_table_whatever_column_count(&connection));
228228

229-
db_checker.apply().await.unwrap();
230-
assert_eq!(0, get_table_whatever_column_count(&connection).await);
229+
db_checker.apply().unwrap();
230+
assert_eq!(0, get_table_whatever_column_count(&connection));
231231

232232
let alterations = "create table whatever (thing_id integer); insert into whatever (thing_id) values (1), (2), (3), (4);";
233233
let migration = SqlMigration {
234234
version: 1,
235235
alterations: alterations.to_string(),
236236
};
237237
db_checker.add_migration(migration);
238-
db_checker.apply().await.unwrap();
239-
assert_eq!(1, get_table_whatever_column_count(&connection).await);
240-
check_database_version(&connection, 1).await;
238+
db_checker.apply().unwrap();
239+
assert_eq!(1, get_table_whatever_column_count(&connection));
240+
check_database_version(&connection, 1);
241241

242-
db_checker.apply().await.unwrap();
243-
assert_eq!(1, get_table_whatever_column_count(&connection).await);
244-
check_database_version(&connection, 1).await;
242+
db_checker.apply().unwrap();
243+
assert_eq!(1, get_table_whatever_column_count(&connection));
244+
check_database_version(&connection, 1);
245245

246246
let alterations = "alter table whatever add column thing_content text; update whatever set thing_content = 'some content'";
247247
let migration = SqlMigration {
248248
version: 2,
249249
alterations: alterations.to_string(),
250250
};
251251
db_checker.add_migration(migration);
252-
db_checker.apply().await.unwrap();
253-
assert_eq!(2, get_table_whatever_column_count(&connection).await);
254-
check_database_version(&connection, 2).await;
252+
db_checker.apply().unwrap();
253+
assert_eq!(2, get_table_whatever_column_count(&connection));
254+
check_database_version(&connection, 2);
255255

256256
// in the test below both migrations are declared in reversed order to
257257
// ensure they are played in the right order. The last one depends on
@@ -268,13 +268,13 @@ mod tests {
268268
alterations: alterations.to_string(),
269269
};
270270
db_checker.add_migration(migration);
271-
db_checker.apply().await.unwrap();
272-
assert_eq!(4, get_table_whatever_column_count(&connection).await);
273-
check_database_version(&connection, 4).await;
271+
db_checker.apply().unwrap();
272+
assert_eq!(4, get_table_whatever_column_count(&connection));
273+
check_database_version(&connection, 4);
274274
}
275275

276-
#[tokio::test]
277-
async fn starting_with_migration() {
276+
#[test]
277+
fn starting_with_migration() {
278278
let (_filepath, connection) = create_sqlite_file("starting_with_migration").unwrap();
279279
let mut db_checker = DatabaseVersionChecker::new(
280280
slog_scope::logger(),
@@ -288,16 +288,16 @@ mod tests {
288288
alterations: alterations.to_string(),
289289
};
290290
db_checker.add_migration(migration);
291-
db_checker.apply().await.unwrap();
292-
assert_eq!(1, get_table_whatever_column_count(&connection).await);
293-
check_database_version(&connection, 1).await;
291+
db_checker.apply().unwrap();
292+
assert_eq!(1, get_table_whatever_column_count(&connection));
293+
check_database_version(&connection, 1);
294294
}
295295

296-
#[tokio::test]
296+
#[test]
297297
/// This test case ensure that when multiple migrations are played and one fails:
298298
/// * previous migrations are ok and the database version is updated
299299
/// * further migrations are not played.
300-
async fn test_failing_migration() {
300+
fn test_failing_migration() {
301301
let (_filepath, connection) = create_sqlite_file("test_failing_migration").unwrap();
302302
let mut db_checker = DatabaseVersionChecker::new(
303303
slog_scope::logger(),
@@ -323,12 +323,12 @@ mod tests {
323323
alterations: alterations.to_string(),
324324
};
325325
db_checker.add_migration(migration);
326-
db_checker.apply().await.unwrap_err();
327-
check_database_version(&connection, 1).await;
326+
db_checker.apply().unwrap_err();
327+
check_database_version(&connection, 1);
328328
}
329329

330-
#[tokio::test]
331-
async fn test_fail_downgrading() {
330+
#[test]
331+
fn test_fail_downgrading() {
332332
let (_filepath, connection) = create_sqlite_file("test_fail_downgrading").unwrap();
333333
let mut db_checker = DatabaseVersionChecker::new(
334334
slog_scope::logger(),
@@ -341,8 +341,8 @@ mod tests {
341341
alterations: alterations.to_string(),
342342
};
343343
db_checker.add_migration(migration);
344-
db_checker.apply().await.unwrap();
345-
check_database_version(&connection, 1).await;
344+
db_checker.apply().unwrap();
345+
check_database_version(&connection, 1);
346346

347347
// re instantiate a new checker with no migration registered (version 0).
348348
let db_checker = DatabaseVersionChecker::new(
@@ -351,9 +351,9 @@ mod tests {
351351
&connection,
352352
);
353353
assert!(
354-
db_checker.apply().await.is_err(),
354+
db_checker.apply().is_err(),
355355
"using an old version with an up to date database should fail"
356356
);
357-
check_database_version(&connection, 1).await;
357+
check_database_version(&connection, 1);
358358
}
359359
}

0 commit comments

Comments
 (0)