@@ -2650,6 +2650,67 @@ mod migration_156 {
2650
2650
}
2651
2651
}
2652
2652
2653
+ const BP_OXIMETER_READ_POLICY_ID_0 : & str =
2654
+ "5cb42909-d94a-4903-be72-330eea0325d9" ;
2655
+ const BP_OXIMETER_READ_POLICY_ID_1 : & str =
2656
+ "142b62c2-9348-4530-9eed-7077351fb94b" ;
2657
+ const BP_OXIMETER_READ_POLICY_ID_2 : & str =
2658
+ "3b5b7861-03aa-420a-a057-0a14347dc4c0" ;
2659
+ const BP_OXIMETER_READ_POLICY_ID_3 : & str =
2660
+ "de7ab4c0-30d4-4e9e-b620-3a959a9d59dd" ;
2661
+
2662
+ // Insert two blueprints and 4 oximeter read policies, two of which do not have
2663
+ // a corresponding blueprint
2664
+ fn before_164_0_0 < ' a > ( ctx : & ' a MigrationContext < ' a > ) -> BoxFuture < ' a , ( ) > {
2665
+ Box :: pin ( async move {
2666
+ ctx. client
2667
+ . batch_execute (
2668
+ & format ! ( "
2669
+ INSERT INTO omicron.public.blueprint
2670
+ (id, parent_blueprint_id, time_created, creator, comment, internal_dns_version, external_dns_version, cockroachdb_fingerprint, cockroachdb_setting_preserve_downgrade, target_release_minimum_generation)
2671
+ VALUES
2672
+ (
2673
+ '{BP_OXIMETER_READ_POLICY_ID_0}', NULL, now(), 'bob', 'hi', 1, 1, 'fingerprint', NULL, 1
2674
+ ),
2675
+ (
2676
+ '{BP_OXIMETER_READ_POLICY_ID_1}', NULL, now(), 'bab', 'hi', 1, 1, 'fingerprint', NULL, 1
2677
+ );
2678
+
2679
+ INSERT INTO omicron.public.bp_oximeter_read_policy
2680
+ (blueprint_id, version, oximeter_read_mode)
2681
+ VALUES
2682
+ ('{BP_OXIMETER_READ_POLICY_ID_0}', 1, 'cluster'),
2683
+ ('{BP_OXIMETER_READ_POLICY_ID_1}', 2, 'cluster'),
2684
+ ('{BP_OXIMETER_READ_POLICY_ID_2}', 3, 'cluster'),
2685
+ ('{BP_OXIMETER_READ_POLICY_ID_3}', 4, 'cluster')
2686
+ " ) ,
2687
+ )
2688
+ . await
2689
+ . expect ( "failed to insert pre-migration rows for 163" ) ;
2690
+ } )
2691
+ }
2692
+
2693
+ // Validate that rows that do not have a corresponding blueprint are gone
2694
+ fn after_164_0_0 < ' a > ( ctx : & ' a MigrationContext < ' a > ) -> BoxFuture < ' a , ( ) > {
2695
+ Box :: pin ( async move {
2696
+ let rows = ctx
2697
+ . client
2698
+ . query (
2699
+ "SELECT blueprint_id FROM omicron.public.bp_oximeter_read_policy ORDER BY blueprint_id;" ,
2700
+ & [ ] ,
2701
+ )
2702
+ . await
2703
+ . expect ( "failed to query post-migration bp_oximeter_read_policy table" ) ;
2704
+ assert_eq ! ( rows. len( ) , 2 ) ;
2705
+
2706
+ let id_1: Uuid = ( & rows[ 0 ] ) . get :: < & str , Uuid > ( "blueprint_id" ) ;
2707
+ assert_eq ! ( id_1. to_string( ) , BP_OXIMETER_READ_POLICY_ID_1 ) ;
2708
+
2709
+ let id_2: Uuid = ( & rows[ 1 ] ) . get :: < & str , Uuid > ( "blueprint_id" ) ;
2710
+ assert_eq ! ( id_2. to_string( ) , BP_OXIMETER_READ_POLICY_ID_0 ) ;
2711
+ } )
2712
+ }
2713
+
2653
2714
// Lazily initializes all migration checks. The combination of Rust function
2654
2715
// pointers and async makes defining a static table fairly painful, so we're
2655
2716
// using lazy initialization instead.
@@ -2736,6 +2797,10 @@ fn get_migration_checks() -> BTreeMap<Version, DataMigrationFns> {
2736
2797
. before ( migration_156:: before)
2737
2798
. after ( migration_156:: after) ,
2738
2799
) ;
2800
+ map. insert (
2801
+ Version :: new ( 164 , 0 , 0 ) ,
2802
+ DataMigrationFns :: new ( ) . before ( before_164_0_0) . after ( after_164_0_0) ,
2803
+ ) ;
2739
2804
2740
2805
map
2741
2806
}
0 commit comments