@@ -4129,12 +4129,19 @@ fn after_222_0_0<'a>(ctx: &'a MigrationContext<'a>) -> BoxFuture<'a, ()> {
41294129// Migration 229 fixes column ordering in console_session and device_access_token.
41304130// The "id" column was added via ALTER TABLE in migration 145, placing it at the
41314131// end. This migration recreates the tables with "id" as the first column.
4132+ // It also drops console sessions created more than 24 hours ago.
41324133const SESSION_229_ID : Uuid =
41334134 Uuid :: from_u128 ( 0x22900001_0000_0000_0000_000000000001 ) ;
41344135const SESSION_229_TOKEN : & str = "tok-console-229-migration-test" ;
41354136const SESSION_229_SILO_USER : Uuid =
41364137 Uuid :: from_u128 ( 0x22900001_0000_0000_0000_000000000002 ) ;
41374138
4139+ const SESSION_229_OLD_ID : Uuid =
4140+ Uuid :: from_u128 ( 0x22900001_0000_0000_0000_000000000003 ) ;
4141+ const SESSION_229_OLD_TOKEN : & str = "tok-console-229-old-session" ;
4142+ const SESSION_229_OLD_SILO_USER : Uuid =
4143+ Uuid :: from_u128 ( 0x22900001_0000_0000_0000_000000000004 ) ;
4144+
41384145const DEVICE_229_ID : Uuid =
41394146 Uuid :: from_u128 ( 0x22900002_0000_0000_0000_000000000001 ) ;
41404147const DEVICE_229_TOKEN : & str = "tok-device-229-migration-test" ;
@@ -4148,6 +4155,8 @@ fn before_229_0_0<'a>(ctx: &'a MigrationContext<'a>) -> BoxFuture<'a, ()> {
41484155 Box :: pin ( async move {
41494156 // Insert test data into console_session and device_access_token.
41504157 // These tables currently have "id" as the last column (from migration 145).
4158+ // We insert two console sessions: one recent (should be kept) and one
4159+ // created over 24 hours ago (should be dropped).
41514160 ctx. client
41524161 . batch_execute ( & format ! (
41534162 "
@@ -4156,6 +4165,13 @@ fn before_229_0_0<'a>(ctx: &'a MigrationContext<'a>) -> BoxFuture<'a, ()> {
41564165 VALUES
41574166 ('{SESSION_229_ID}', '{SESSION_229_TOKEN}', now(), now(), '{SESSION_229_SILO_USER}');
41584167
4168+ INSERT INTO omicron.public.console_session
4169+ (id, token, time_created, time_last_used, silo_user_id)
4170+ VALUES
4171+ ('{SESSION_229_OLD_ID}', '{SESSION_229_OLD_TOKEN}',
4172+ now() - INTERVAL '48 hours', now() - INTERVAL '48 hours',
4173+ '{SESSION_229_OLD_SILO_USER}');
4174+
41594175 INSERT INTO omicron.public.device_access_token
41604176 (id, token, client_id, device_code, silo_user_id, time_requested, time_created)
41614177 VALUES
@@ -4172,7 +4188,7 @@ fn after_229_0_0<'a>(ctx: &'a MigrationContext<'a>) -> BoxFuture<'a, ()> {
41724188 Box :: pin ( async move {
41734189 // Verify data was preserved after the column reordering migration.
41744190
4175- // Check console_session
4191+ // Check that the recent console_session was kept
41764192 let rows = ctx
41774193 . client
41784194 . query (
@@ -4184,7 +4200,11 @@ fn after_229_0_0<'a>(ctx: &'a MigrationContext<'a>) -> BoxFuture<'a, ()> {
41844200 )
41854201 . await
41864202 . expect ( "failed to query post-migration console_session" ) ;
4187- assert_eq ! ( rows. len( ) , 1 , "console_session row should still exist" ) ;
4203+ assert_eq ! (
4204+ rows. len( ) ,
4205+ 1 ,
4206+ "recent console_session row should still exist"
4207+ ) ;
41884208
41894209 let id: Uuid = rows[ 0 ] . get ( "id" ) ;
41904210 assert_eq ! ( id, SESSION_229_ID ) ;
@@ -4193,6 +4213,26 @@ fn after_229_0_0<'a>(ctx: &'a MigrationContext<'a>) -> BoxFuture<'a, ()> {
41934213 let silo_user_id: Uuid = rows[ 0 ] . get ( "silo_user_id" ) ;
41944214 assert_eq ! ( silo_user_id, SESSION_229_SILO_USER ) ;
41954215
4216+ // Check that the old (>24h) console_session was dropped
4217+ let rows = ctx
4218+ . client
4219+ . query (
4220+ & format ! (
4221+ "SELECT id FROM omicron.public.console_session
4222+ WHERE id = '{SESSION_229_OLD_ID}'"
4223+ ) ,
4224+ & [ ] ,
4225+ )
4226+ . await
4227+ . expect (
4228+ "failed to query post-migration console_session for old row" ,
4229+ ) ;
4230+ assert_eq ! (
4231+ rows. len( ) ,
4232+ 0 ,
4233+ "console_session row older than 24h should have been dropped"
4234+ ) ;
4235+
41964236 // Check device_access_token
41974237 let rows = ctx
41984238 . client
0 commit comments