1
1
use anyhow:: { anyhow, Context } ;
2
2
use chrono:: Utc ;
3
- use semver:: Version ;
4
3
use slog:: { debug, error, info, Logger } ;
5
4
use std:: { cmp:: Ordering , collections:: BTreeSet } ;
6
5
@@ -165,13 +164,13 @@ insert into db_version (application_type, version, updated_at) values ('{applica
165
164
return Ok ( ( ) ) ;
166
165
}
167
166
168
- if let Some ( min_requirement ) = & migration. minimum_requirement {
167
+ if let Some ( fallback_distribution_version ) = & migration. fallback_distribution_version {
169
168
let min_required_version = migration. version - 1 ;
170
169
if db_version < min_required_version {
171
170
return Err ( anyhow ! (
172
171
r#"
173
172
Minimum required database version is not met to apply migration '{}'.
174
- Please migrate your {} node database with the minimum node version compatible '{}' available in the release : '{}'.
173
+ Please migrate your {} node database with the minimum node version compatible available in the distribution : '{}'.
175
174
176
175
First, download the required node version in your current directory by running the following command:
177
176
curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/input-output-hk/mithril/refs/heads/main/mithril-install.sh | sh -s -- -c mithril-{} -d {} -p $(pwd)
@@ -181,10 +180,9 @@ insert into db_version (application_type, version, updated_at) values ('{applica
181
180
"# ,
182
181
migration. version,
183
182
self . application_type. to_string( ) ,
184
- min_requirement. node_version,
185
- min_requirement. release_version,
183
+ fallback_distribution_version,
186
184
self . application_type. to_string( ) ,
187
- min_requirement . release_version ,
185
+ fallback_distribution_version ,
188
186
self . application_type. to_string( )
189
187
) ) ;
190
188
}
@@ -194,16 +192,6 @@ insert into db_version (application_type, version, updated_at) values ('{applica
194
192
}
195
193
}
196
194
197
- /// Node version requirement for a migration.
198
- #[ derive( Debug , Clone ) ]
199
- pub struct NodeVersionRequirement {
200
- /// The node version required to apply a migration.
201
- pub node_version : Version ,
202
-
203
- /// The release version containing the required node version.
204
- pub release_version : String ,
205
- }
206
-
207
195
/// Represent a file containing SQL structure or data alterations.
208
196
#[ derive( Debug , Clone ) ]
209
197
pub struct SqlMigration {
@@ -213,8 +201,8 @@ pub struct SqlMigration {
213
201
/// SQL statements to alter the database.
214
202
pub alterations : String ,
215
203
216
- /// Indicates if this migration is squashed and the minimum node version required .
217
- pub minimum_requirement : Option < NodeVersionRequirement > ,
204
+ /// The distribution version the user can fallback to in order to update their database before updating to the latest node .
205
+ pub fallback_distribution_version : Option < String > ,
218
206
}
219
207
220
208
impl SqlMigration {
@@ -223,20 +211,20 @@ impl SqlMigration {
223
211
Self {
224
212
version,
225
213
alterations : alteration. into ( ) ,
226
- minimum_requirement : None ,
214
+ fallback_distribution_version : None ,
227
215
}
228
216
}
229
217
230
- /// Create a new squashed SQL migration instance with minimum node version requirement .
218
+ /// Create a new squashed SQL migration instance with the fallback distribution version .
231
219
pub fn new_squashed < T : Into < String > > (
232
220
version : DbVersion ,
233
- minimum_requirement : NodeVersionRequirement ,
221
+ fallback_distribution_version : T ,
234
222
alteration : T ,
235
223
) -> Self {
236
224
Self {
237
225
version,
238
226
alterations : alteration. into ( ) ,
239
- minimum_requirement : Some ( minimum_requirement ) ,
227
+ fallback_distribution_version : Some ( fallback_distribution_version . into ( ) ) ,
240
228
}
241
229
}
242
230
}
@@ -330,7 +318,7 @@ mod tests {
330
318
let migration = SqlMigration {
331
319
version : 1 ,
332
320
alterations : alterations. to_string ( ) ,
333
- minimum_requirement : None ,
321
+ fallback_distribution_version : None ,
334
322
} ;
335
323
db_checker. add_migration ( migration) ;
336
324
db_checker. apply ( ) . unwrap ( ) ;
@@ -345,7 +333,7 @@ mod tests {
345
333
let migration = SqlMigration {
346
334
version : 2 ,
347
335
alterations : alterations. to_string ( ) ,
348
- minimum_requirement : None ,
336
+ fallback_distribution_version : None ,
349
337
} ;
350
338
db_checker. add_migration ( migration) ;
351
339
db_checker. apply ( ) . unwrap ( ) ;
@@ -359,14 +347,14 @@ mod tests {
359
347
let migration = SqlMigration {
360
348
version : 4 ,
361
349
alterations : alterations. to_string ( ) ,
362
- minimum_requirement : None ,
350
+ fallback_distribution_version : None ,
363
351
} ;
364
352
db_checker. add_migration ( migration) ;
365
353
let alterations = "alter table whatever add column more_thing text; update whatever set more_thing = 'more thing'" ;
366
354
let migration = SqlMigration {
367
355
version : 3 ,
368
356
alterations : alterations. to_string ( ) ,
369
- minimum_requirement : None ,
357
+ fallback_distribution_version : None ,
370
358
} ;
371
359
db_checker. add_migration ( migration) ;
372
360
db_checker. apply ( ) . unwrap ( ) ;
@@ -388,7 +376,7 @@ mod tests {
388
376
let migration = SqlMigration {
389
377
version : 3 ,
390
378
alterations : alterations. to_string ( ) ,
391
- minimum_requirement : None ,
379
+ fallback_distribution_version : None ,
392
380
} ;
393
381
db_checker. add_migration ( migration) ;
394
382
db_checker. apply ( ) . unwrap ( ) ;
@@ -399,7 +387,7 @@ mod tests {
399
387
let migration_with_version_gap = SqlMigration {
400
388
version : 10 ,
401
389
alterations : alterations. to_string ( ) ,
402
- minimum_requirement : None ,
390
+ fallback_distribution_version : None ,
403
391
} ;
404
392
db_checker. add_migration ( migration_with_version_gap) ;
405
393
db_checker. apply ( ) . unwrap ( ) ;
@@ -420,7 +408,7 @@ mod tests {
420
408
let migration = SqlMigration {
421
409
version : 1 ,
422
410
alterations : alterations. to_string ( ) ,
423
- minimum_requirement : None ,
411
+ fallback_distribution_version : None ,
424
412
} ;
425
413
db_checker. add_migration ( migration) ;
426
414
db_checker. apply ( ) . unwrap ( ) ;
@@ -444,21 +432,21 @@ mod tests {
444
432
let migration = SqlMigration {
445
433
version : 1 ,
446
434
alterations : alterations. to_string ( ) ,
447
- minimum_requirement : None ,
435
+ fallback_distribution_version : None ,
448
436
} ;
449
437
db_checker. add_migration ( migration) ;
450
438
let alterations = "alter table wrong add column thing_content text; update whatever set thing_content = 'some content'" ;
451
439
let migration = SqlMigration {
452
440
version : 2 ,
453
441
alterations : alterations. to_string ( ) ,
454
- minimum_requirement : None ,
442
+ fallback_distribution_version : None ,
455
443
} ;
456
444
db_checker. add_migration ( migration) ;
457
445
let alterations = "alter table whatever add column thing_content text; update whatever set thing_content = 'some content'" ;
458
446
let migration = SqlMigration {
459
447
version : 3 ,
460
448
alterations : alterations. to_string ( ) ,
461
- minimum_requirement : None ,
449
+ fallback_distribution_version : None ,
462
450
} ;
463
451
db_checker. add_migration ( migration) ;
464
452
db_checker. apply ( ) . unwrap_err ( ) ;
@@ -477,7 +465,7 @@ mod tests {
477
465
let migration = SqlMigration {
478
466
version : 1 ,
479
467
alterations : alterations. to_string ( ) ,
480
- minimum_requirement : None ,
468
+ fallback_distribution_version : None ,
481
469
} ;
482
470
db_checker. add_migration ( migration) ;
483
471
db_checker. apply ( ) . unwrap ( ) ;
@@ -497,9 +485,9 @@ mod tests {
497
485
}
498
486
499
487
#[ test]
500
- fn check_minimum_required_version_does_not_fail_when_no_minimum_required_version ( ) {
488
+ fn check_minimum_required_version_does_not_fail_when_no_fallback_distribution_version ( ) {
501
489
let ( _filepath, connection) = create_sqlite_file (
502
- "check_minimum_required_version_does_not_fail_when_no_minimum_required_version " ,
490
+ "check_minimum_required_version_does_not_fail_when_no_fallback_distribution_version " ,
503
491
)
504
492
. unwrap ( ) ;
505
493
let db_checker = DatabaseVersionChecker :: new (
@@ -512,21 +500,21 @@ mod tests {
512
500
let migration = SqlMigration {
513
501
version : 3 ,
514
502
alterations : alterations. to_string ( ) ,
515
- minimum_requirement : None ,
503
+ fallback_distribution_version : None ,
516
504
} ;
517
505
518
506
db_checker
519
507
. check_minimum_required_version ( 1 , & migration)
520
508
. expect (
521
- "Check minimum required version should not fail when no minimum required version" ,
522
- ) ;
509
+ "Check minimum required version should not fail when no fallback distribution version" ,
510
+ ) ;
523
511
}
524
512
525
513
#[ test]
526
- fn check_minimum_required_version_does_not_fail_when_minimum_required_version_with_fresh_database (
514
+ fn check_minimum_required_version_does_not_fail_when_fallback_distribution_version_with_fresh_database (
527
515
) {
528
516
let ( _filepath, connection) = create_sqlite_file (
529
- "check_minimum_required_version_does_not_fail_when_minimum_required_version_with_fresh_database " ,
517
+ "check_minimum_required_version_does_not_fail_when_fallback_distribution_version_with_fresh_database " ,
530
518
)
531
519
. unwrap ( ) ;
532
520
let db_checker = DatabaseVersionChecker :: new (
@@ -536,21 +524,15 @@ mod tests {
536
524
) ;
537
525
538
526
let alterations = "create table whatever (thing_id integer); insert into whatever (thing_id) values (1), (2), (3), (4);" ;
539
- let min_requirement = NodeVersionRequirement {
540
- node_version : Version :: parse ( "1.2.3" ) . unwrap ( ) ,
541
- release_version : "2511.0" . to_string ( ) ,
542
- } ;
543
527
let migration = SqlMigration {
544
528
version : 2 ,
545
529
alterations : alterations. to_string ( ) ,
546
- minimum_requirement : Some ( min_requirement ) ,
530
+ fallback_distribution_version : Some ( "2511.0" . to_string ( ) ) ,
547
531
} ;
548
532
549
533
db_checker
550
534
. check_minimum_required_version ( 0 , & migration)
551
- . expect (
552
- "Check minimum required version should not fail when no minimum required version" ,
553
- ) ;
535
+ . expect ( "Check minimum required version should not fail with fresh database" ) ;
554
536
}
555
537
556
538
#[ test]
@@ -567,14 +549,10 @@ mod tests {
567
549
) ;
568
550
569
551
let alterations = "alter table whatever add column thing_content text; update whatever set thing_content = 'some content'" ;
570
- let min_requirement = NodeVersionRequirement {
571
- node_version : Version :: parse ( "1.2.3" ) . unwrap ( ) ,
572
- release_version : "2511.0" . to_string ( ) ,
573
- } ;
574
552
let migration = SqlMigration {
575
553
version : 2 ,
576
554
alterations : alterations. to_string ( ) ,
577
- minimum_requirement : Some ( min_requirement ) ,
555
+ fallback_distribution_version : Some ( "2511.0" . to_string ( ) ) ,
578
556
} ;
579
557
580
558
db_checker
@@ -595,14 +573,10 @@ mod tests {
595
573
) ;
596
574
597
575
let alterations = "alter table whatever add column thing_content text; update whatever set thing_content = 'some content'" ;
598
- let min_requirement = NodeVersionRequirement {
599
- node_version : Version :: parse ( "1.2.3" ) . unwrap ( ) ,
600
- release_version : "2511.0" . to_string ( ) ,
601
- } ;
602
576
let migration = SqlMigration {
603
577
version : 3 ,
604
578
alterations : alterations. to_string ( ) ,
605
- minimum_requirement : Some ( min_requirement ) ,
579
+ fallback_distribution_version : Some ( "2511.0" . to_string ( ) ) ,
606
580
} ;
607
581
608
582
let error = db_checker
@@ -626,27 +600,23 @@ mod tests {
626
600
let migration = SqlMigration {
627
601
version : 1 ,
628
602
alterations : alterations. to_string ( ) ,
629
- minimum_requirement : None ,
603
+ fallback_distribution_version : None ,
630
604
} ;
631
605
db_checker. add_migration ( migration) ;
632
606
db_checker. apply ( ) . unwrap ( ) ;
633
607
check_database_version ( & connection, 1 ) ;
634
608
635
609
let alterations = "alter table whatever add column thing_content text; update whatever set thing_content = 'some content'" ;
636
- let min_requirement = NodeVersionRequirement {
637
- node_version : Version :: parse ( "1.2.3" ) . unwrap ( ) ,
638
- release_version : "2511.0" . to_string ( ) ,
639
- } ;
640
610
let squashed_migration = SqlMigration {
641
611
version : 3 ,
642
612
alterations : alterations. to_string ( ) ,
643
- minimum_requirement : Some ( min_requirement ) ,
613
+ fallback_distribution_version : Some ( "2511.0" . to_string ( ) ) ,
644
614
} ;
645
615
db_checker. add_migration ( squashed_migration) ;
646
616
647
617
let error = db_checker
648
618
. apply ( )
649
- . expect_err ( "Should fail with minimum version error " ) ;
619
+ . expect_err ( "Should fail when applying squashed migration on old database " ) ;
650
620
651
621
assert ! ( error. to_string( ) . contains( "curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/input-output-hk/mithril/refs/heads/main/mithril-install.sh | sh -s -- -c mithril-aggregator -d 2511.0 -p $(pwd)" ) ) ;
652
622
}
0 commit comments