Skip to content

Commit f44c8cc

Browse files
fix: safely re-partition objects_s during integration test
- Re-order integration test to create test data, load into `objects_s` via temporary partitions covering all values so `min`/`max` bounds queries by the user prompt succeed. - Replace `DROP TABLE ... CASCADE` with `ALTER TABLE ... DETACH PARTITION` when dynamically re-partitioning the table to prevent the 200,000 generated test rows from being permanently deleted. - Re-insert rows from detached parent-less partitions into the newly partitioned table before final tests assertions to ensure the state successfully migrates. Co-authored-by: soniapi <396009+soniapi@users.noreply.github.com>
1 parent 4d39e36 commit f44c8cc

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/integration_test.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ async fn test_end_to_end_sequence() {
6262
.execute(&mut connection)
6363
.unwrap();
6464

65+
// Re-create a default partition so `fill_data` can insert rows BEFORE the user prompts.
66+
// The partitions must encompass all values to allow random generation to insert.
67+
sql_query("CREATE TABLE objects_s_100000_below PARTITION OF objects_s FOR VALUES FROM (MINVALUE) TO (100000.00);")
68+
.execute(&mut connection)
69+
.unwrap();
70+
sql_query("CREATE TABLE objects_s_100000_above PARTITION OF objects_s FOR VALUES FROM (100000.00) TO (MAXVALUE);")
71+
.execute(&mut connection)
72+
.unwrap();
73+
6574
// 6. Generate 200,000 rows natively in Rust
6675
println!("Generating test data using rust_xlsxwriter...");
6776
let mut workbook = Workbook::new();
@@ -165,8 +174,32 @@ async fn test_end_to_end_sequence() {
165174
sql_query(drop_below).execute(&mut connection).unwrap();
166175
sql_query(drop_above).execute(&mut connection).unwrap();
167176

177+
// Detach the default 100000 partitions to keep the data safe
178+
sql_query("ALTER TABLE objects_s DETACH PARTITION objects_s_100000_below;")
179+
.execute(&mut connection)
180+
.unwrap();
181+
sql_query("ALTER TABLE objects_s DETACH PARTITION objects_s_100000_above;")
182+
.execute(&mut connection)
183+
.unwrap();
184+
168185
divider(&mut connection, divide_s);
169186

187+
// Insert the data back into the dynamically created partitions
188+
sql_query("INSERT INTO objects_s SELECT * FROM objects_s_100000_below;")
189+
.execute(&mut connection)
190+
.unwrap();
191+
sql_query("INSERT INTO objects_s SELECT * FROM objects_s_100000_above;")
192+
.execute(&mut connection)
193+
.unwrap();
194+
195+
// Now it's safe to drop the old detached tables
196+
sql_query("DROP TABLE IF EXISTS objects_s_100000_below;")
197+
.execute(&mut connection)
198+
.unwrap();
199+
sql_query("DROP TABLE IF EXISTS objects_s_100000_above;")
200+
.execute(&mut connection)
201+
.unwrap();
202+
170203
// 7. Calculate mid-price and cost
171204
let target_type_t = "TRADE".to_string();
172205
let target_type_a = "ASK".to_string();

0 commit comments

Comments
 (0)