@@ -4,8 +4,10 @@ use etl::store::cleanup::CleanupStore;
4
4
use etl:: store:: schema:: SchemaStore ;
5
5
use etl:: store:: state:: StateStore ;
6
6
use etl:: test_utils:: database:: spawn_source_database_for_store;
7
+ use etl_postgres:: replication:: connect_to_source_database;
7
8
use etl_postgres:: types:: { ColumnSchema , TableId , TableName , TableSchema } ;
8
9
use etl_telemetry:: tracing:: init_test_tracing;
10
+ use sqlx:: postgres:: types:: Oid as SqlxTableId ;
9
11
use tokio_postgres:: types:: { PgLsn , Type as PgType } ;
10
12
11
13
fn create_sample_table_schema ( ) -> TableSchema {
@@ -128,6 +130,20 @@ async fn test_state_store_rollback() {
128
130
. await
129
131
. unwrap ( ) ;
130
132
133
+ // Verify two rows exist before rollback (init + data_sync)
134
+ let pool = connect_to_source_database ( & database. config , 1 , 1 )
135
+ . await
136
+ . expect ( "Failed to connect to source database with sqlx" ) ;
137
+ let count_before: i64 = sqlx:: query_scalar (
138
+ "select count(*) from etl.replication_state where pipeline_id = $1 and table_id = $2" ,
139
+ )
140
+ . bind ( pipeline_id as i64 )
141
+ . bind ( SqlxTableId ( table_id. into_inner ( ) ) )
142
+ . fetch_one ( & pool)
143
+ . await
144
+ . unwrap ( ) ;
145
+ assert_eq ! ( count_before, 2 ) ;
146
+
131
147
// Verify current state
132
148
let state = store. get_table_replication_state ( table_id) . await . unwrap ( ) ;
133
149
assert_eq ! ( state, Some ( data_sync_phase) ) ;
@@ -143,6 +159,17 @@ async fn test_state_store_rollback() {
143
159
let state = store. get_table_replication_state ( table_id) . await . unwrap ( ) ;
144
160
assert_eq ! ( state, Some ( init_phase) ) ;
145
161
162
+ // Verify the rolled-from row was deleted to avoid buildup
163
+ let count_after: i64 = sqlx:: query_scalar (
164
+ "select count(*) from etl.replication_state where pipeline_id = $1 and table_id = $2" ,
165
+ )
166
+ . bind ( pipeline_id as i64 )
167
+ . bind ( SqlxTableId ( table_id. into_inner ( ) ) )
168
+ . fetch_one ( & pool)
169
+ . await
170
+ . unwrap ( ) ;
171
+ assert_eq ! ( count_after, 1 ) ;
172
+
146
173
// Test rollback when there's no previous state
147
174
let result = store. rollback_table_replication_state ( table_id) . await ;
148
175
assert ! ( result. is_err( ) ) ;
0 commit comments