@@ -1754,6 +1754,106 @@ fn after_125_0_0<'a>(ctx: &'a MigrationContext<'a>) -> BoxFuture<'a, ()> {
17541754 } )
17551755}
17561756
1757+ fn before_133_0_0 < ' a > ( ctx : & ' a MigrationContext < ' a > ) -> BoxFuture < ' a , ( ) > {
1758+ Box :: pin ( async {
1759+ // This VMM will have a sled_resource_vmm record and a VMM record
1760+ let vmm1_id: Uuid =
1761+ "00000000-0000-0000-0000-000000000001" . parse ( ) . unwrap ( ) ;
1762+ // This VMM will have a sled_resource_vmm record only
1763+ let vmm2_id: Uuid =
1764+ "00000000-0000-0000-0000-000000000002" . parse ( ) . unwrap ( ) ;
1765+
1766+ let sled_id = Uuid :: new_v4 ( ) ;
1767+ let instance1_id = Uuid :: new_v4 ( ) ;
1768+ let instance2_id = Uuid :: new_v4 ( ) ;
1769+
1770+ ctx. client
1771+ . batch_execute ( & format ! (
1772+ "
1773+ INSERT INTO sled_resource_vmm (
1774+ id,
1775+ sled_id,
1776+ hardware_threads,
1777+ rss_ram,
1778+ reservoir_ram,
1779+ instance_id
1780+ ) VALUES
1781+ (
1782+ '{vmm1_id}', '{sled_id}', 1, 0, 0, '{instance1_id}'
1783+ ),
1784+ (
1785+ '{vmm2_id}', '{sled_id}', 1, 0, 0, '{instance2_id}'
1786+ );
1787+
1788+ "
1789+ ) )
1790+ . await
1791+ . expect ( "inserted record" ) ;
1792+
1793+ // Only insert a vmm record for one of these reservations
1794+ ctx. client
1795+ . batch_execute ( & format ! (
1796+ "
1797+ INSERT INTO vmm (
1798+ id,
1799+ time_created,
1800+ time_deleted,
1801+ instance_id,
1802+ time_state_updated,
1803+ state_generation,
1804+ sled_id,
1805+ propolis_ip,
1806+ propolis_port,
1807+ state
1808+ ) VALUES (
1809+ '{vmm1_id}',
1810+ now(),
1811+ NULL,
1812+ '{instance1_id}',
1813+ now(),
1814+ 1,
1815+ '{sled_id}',
1816+ 'fd00:1122:3344:104::1',
1817+ 12400,
1818+ 'running'
1819+ );
1820+ "
1821+ ) )
1822+ . await
1823+ . expect ( "inserted record" ) ;
1824+ } )
1825+ }
1826+
1827+ fn after_133_0_0 < ' a > ( ctx : & ' a MigrationContext < ' a > ) -> BoxFuture < ' a , ( ) > {
1828+ Box :: pin ( async {
1829+ // This record should still have a sled_resource_vmm, and be the only
1830+ // one.
1831+ let vmm1_id: Uuid =
1832+ "00000000-0000-0000-0000-000000000001" . parse ( ) . unwrap ( ) ;
1833+
1834+ let rows = ctx
1835+ . client
1836+ . query (
1837+ r#"
1838+ SELECT id FROM sled_resource_vmm
1839+ "# ,
1840+ & [ ] ,
1841+ )
1842+ . await
1843+ . expect ( "loaded sled_resource_vmm rows" ) ;
1844+
1845+ let records = process_rows ( & rows) ;
1846+
1847+ assert_eq ! ( records. len( ) , 1 , "{records:?}" ) ;
1848+
1849+ assert_eq ! (
1850+ records[ 0 ] . values,
1851+ vec![ ColumnValue :: new( "id" , vmm1_id) , ] ,
1852+ "Unexpected sled_resource_vmm record value" ,
1853+ ) ;
1854+ } )
1855+ }
1856+
17571857// Lazily initializes all migration checks. The combination of Rust function
17581858// pointers and async makes defining a static table fairly painful, so we're
17591859// using lazy initialization instead.
@@ -1802,7 +1902,10 @@ fn get_migration_checks() -> BTreeMap<Version, DataMigrationFns> {
18021902 Version :: new ( 125 , 0 , 0 ) ,
18031903 DataMigrationFns :: new ( ) . before ( before_125_0_0) . after ( after_125_0_0) ,
18041904 ) ;
1805-
1905+ map. insert (
1906+ Version :: new ( 133 , 0 , 0 ) ,
1907+ DataMigrationFns :: new ( ) . before ( before_133_0_0) . after ( after_133_0_0) ,
1908+ ) ;
18061909 map
18071910}
18081911
0 commit comments