uni-db 1.1.0

Embedded graph database with OpenCypher queries, vector search, and columnar storage
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
// SPDX-License-Identifier: Apache-2.0
// Copyright 2024-2026 Dragonscale Team

//! Tests for bulk loading API including vertices and edges.

use anyhow::Result;
use std::collections::HashMap;
use uni_db::Uni;
use uni_db::api::bulk::EdgeData;
use uni_db::unival;

const SCHEMA_JSON: &str = r#"{
    "schema_version": 1,
    "labels": {
        "Person": {
            "id": 1,
            "created_at": "2024-01-01T00:00:00Z",
            "state": "Active"
        },
        "Company": {
            "id": 2,
            "created_at": "2024-01-01T00:00:00Z",
            "state": "Active"
        }
    },
    "edge_types": {
        "KNOWS": {
            "id": 1,
            "src_labels": ["Person"],
            "dst_labels": ["Person"],
            "state": "Active"
        },
        "WORKS_AT": {
            "id": 2,
            "src_labels": ["Person"],
            "dst_labels": ["Company"],
            "state": "Active"
        }
    },
    "properties": {
        "Person": {
            "name": { "type": "String", "nullable": true, "added_in": 1, "state": "Active" },
            "age": { "type": "Int32", "nullable": true, "added_in": 1, "state": "Active" }
        },
        "Company": {
            "name": { "type": "String", "nullable": true, "added_in": 1, "state": "Active" }
        },
        "KNOWS": {
            "since": { "type": "Int32", "nullable": true, "added_in": 1, "state": "Active" }
        },
        "WORKS_AT": {
            "role": { "type": "String", "nullable": true, "added_in": 1, "state": "Active" }
        }
    },
    "indexes": []
}"#;

async fn setup_db() -> Result<(Uni, tempfile::TempDir)> {
    let temp_dir = tempfile::tempdir()?;
    let path = temp_dir.path();

    let schema_path = path.join("schema.json");
    tokio::fs::write(&schema_path, SCHEMA_JSON).await?;

    let db = Uni::open(path.to_str().unwrap()).build().await?;
    db.load_schema(&schema_path).await?;

    Ok((db, temp_dir))
}

#[tokio::test]
async fn test_bulk_insert_vertices() -> Result<()> {
    let (db, _temp) = setup_db().await?;

    let s = db.session();
    let tx = s.tx().await?;
    let mut bulk = tx.bulk_writer().batch_size(100).build()?;

    // Insert 250 vertices (will trigger multiple flushes with batch_size=100)
    let mut props = Vec::new();
    for i in 0..250 {
        let mut p: HashMap<String, uni_db::Value> = HashMap::new();
        p.insert("name".to_string(), unival!(format!("Person_{}", i)));
        p.insert("age".to_string(), unival!(i % 100));
        props.push(p);
    }

    let vids = bulk.insert_vertices("Person", props).await?;
    assert_eq!(vids.len(), 250);

    let stats = bulk.commit().await?;
    assert_eq!(stats.vertices_inserted, 250);
    drop(tx);

    // Verify data was persisted
    let result = db
        .session()
        .query("MATCH (p:Person) RETURN count(p) AS c")
        .await?;
    assert_eq!(result.rows()[0].get::<i64>("c")?, 250);

    Ok(())
}

#[tokio::test]
async fn test_bulk_insert_edges() -> Result<()> {
    let (db, _temp) = setup_db().await?;

    // First create some vertices
    let s = db.session();
    let tx = s.tx().await?;
    let mut bulk = tx.bulk_writer().batch_size(100).build()?;

    let mut person_props = Vec::new();
    for i in 0..100 {
        let mut p: HashMap<String, uni_db::Value> = HashMap::new();
        p.insert("name".to_string(), unival!(format!("Person_{}", i)));
        p.insert("age".to_string(), unival!(20 + i % 50));
        person_props.push(p);
    }
    let person_vids = bulk.insert_vertices("Person", person_props).await?;

    let mut company_props = Vec::new();
    for i in 0..10 {
        let mut p: HashMap<String, uni_db::Value> = HashMap::new();
        p.insert("name".to_string(), unival!(format!("Company_{}", i)));
        company_props.push(p);
    }
    let company_vids = bulk.insert_vertices("Company", company_props).await?;

    // Create KNOWS edges (person -> person)
    let mut knows_edges = Vec::new();
    for i in 0..50 {
        let mut props = HashMap::new();
        props.insert("since".to_string(), unival!(2020 + (i % 5)));
        knows_edges.push(EdgeData::new(
            person_vids[i],
            person_vids[(i + 1) % 100],
            props,
        ));
    }
    let knows_eids = bulk.insert_edges("KNOWS", knows_edges).await?;
    assert_eq!(knows_eids.len(), 50);

    // Create WORKS_AT edges (person -> company)
    let mut works_edges = Vec::new();
    for i in 0..100 {
        let mut props = HashMap::new();
        props.insert("role".to_string(), unival!(format!("Role_{}", i % 5)));
        works_edges.push(EdgeData::new(person_vids[i], company_vids[i % 10], props));
    }
    let works_eids = bulk.insert_edges("WORKS_AT", works_edges).await?;
    assert_eq!(works_eids.len(), 100);

    let stats = bulk.commit().await?;
    assert_eq!(stats.vertices_inserted, 110); // 100 persons + 10 companies
    assert_eq!(stats.edges_inserted, 150); // 50 KNOWS + 100 WORKS_AT

    Ok(())
}

#[tokio::test]
async fn test_bulk_abort_clears_buffers() -> Result<()> {
    let (db, _temp) = setup_db().await?;

    let s = db.session();
    let tx = s.tx().await?;
    let mut bulk = tx.bulk_writer().batch_size(1000).build()?; // Large batch to avoid flush

    // Insert vertices (won't be flushed due to large batch size)
    let mut props = Vec::new();
    for i in 0..50 {
        let mut p: HashMap<String, uni_db::Value> = HashMap::new();
        p.insert("name".to_string(), unival!(format!("Person_{}", i)));
        props.push(p);
    }
    let _vids = bulk.insert_vertices("Person", props).await?;

    // Abort instead of commit
    bulk.abort().await?;
    drop(tx);

    // Verify no data was persisted (buffers were cleared before flush)
    // When no dataset exists yet, MATCH returns no rows
    let result = db
        .session()
        .query("MATCH (p:Person) RETURN count(p) AS c")
        .await?;
    if result.is_empty() {
        // No dataset exists - abort worked correctly
    } else {
        // Dataset exists but should have 0 rows
        assert_eq!(result.rows()[0].get::<i64>("c")?, 0);
    }

    Ok(())
}

#[tokio::test]
async fn test_bulk_progress_callback() -> Result<()> {
    use std::sync::Arc;
    use std::sync::atomic::{AtomicUsize, Ordering};

    let (db, _temp) = setup_db().await?;

    let progress_count = Arc::new(AtomicUsize::new(0));
    let progress_count_clone = progress_count.clone();

    let s = db.session();
    let tx = s.tx().await?;
    let mut bulk = tx
        .bulk_writer()
        .batch_size(50)
        .on_progress(move |_progress| {
            progress_count_clone.fetch_add(1, Ordering::SeqCst);
        })
        .build()?;

    // Insert enough to trigger multiple progress callbacks
    let mut props = Vec::new();
    for i in 0..200 {
        let mut p: HashMap<String, uni_db::Value> = HashMap::new();
        p.insert("name".to_string(), unival!(format!("Person_{}", i)));
        props.push(p);
    }
    bulk.insert_vertices("Person", props).await?;
    bulk.commit().await?;

    // Should have received multiple progress callbacks
    assert!(progress_count.load(Ordering::SeqCst) > 0);

    Ok(())
}

#[tokio::test]
async fn test_bulk_edge_with_properties() -> Result<()> {
    let (db, _temp) = setup_db().await?;

    let s = db.session();
    let tx = s.tx().await?;
    let mut bulk = tx.bulk_writer().build()?;

    // Create two persons
    let p1_props = vec![{
        let mut p = HashMap::new();
        p.insert("name".to_string(), unival!("Alice"));
        p.insert("age".to_string(), unival!(30));
        p
    }];
    let p2_props = vec![{
        let mut p = HashMap::new();
        p.insert("name".to_string(), unival!("Bob"));
        p.insert("age".to_string(), unival!(25));
        p
    }];

    let p1_vids = bulk.insert_vertices("Person", p1_props).await?;
    let p2_vids = bulk.insert_vertices("Person", p2_props).await?;

    // Create edge with properties
    let mut edge_props = HashMap::new();
    edge_props.insert("since".to_string(), unival!(2020));

    let edges = vec![EdgeData::new(p1_vids[0], p2_vids[0], edge_props)];
    let eids = bulk.insert_edges("KNOWS", edges).await?;
    assert_eq!(eids.len(), 1);

    bulk.commit().await?;
    drop(tx);

    // Verify edge exists with property
    // Note: Edge property queries may require specific query patterns
    let result = db
        .session()
        .query("MATCH (a:Person)-[r:KNOWS]->(b:Person) RETURN a.name, b.name")
        .await?;
    assert_eq!(result.len(), 1);

    Ok(())
}

#[tokio::test]
async fn test_bulk_async_indexes_returns_immediately() -> Result<()> {
    use uni_store::storage::IndexRebuildStatus;

    let (db, _temp) = setup_db().await?;

    let s = db.session();
    let tx = s.tx().await?;
    let mut bulk = tx
        .bulk_writer()
        .async_indexes(true)
        .batch_size(100)
        .build()?;

    // Insert vertices
    let mut props = Vec::new();
    for i in 0..100 {
        let mut p: HashMap<String, uni_db::Value> = HashMap::new();
        p.insert("name".to_string(), unival!(format!("Person_{}", i)));
        p.insert("age".to_string(), unival!(i % 100));
        props.push(p);
    }
    bulk.insert_vertices("Person", props).await?;

    let stats = bulk.commit().await?;
    drop(tx);

    // In async mode, indexes_pending should be true
    assert!(stats.indexes_pending);

    // Data should be queryable immediately (via full scan)
    let result = db
        .session()
        .query("MATCH (p:Person) RETURN count(p) AS c")
        .await?;
    assert_eq!(result.rows()[0].get::<i64>("c")?, 100);

    // Check initial status - should have pending or in-progress tasks
    let status = db.indexes().rebuild_status().await?;
    // Status may be empty if no indexes defined, or have tasks if indexes exist
    if !status.is_empty() {
        // Verify task structure is correct
        for task in &status {
            assert!(!task.label.is_empty());
            assert!(
                task.status == IndexRebuildStatus::Pending
                    || task.status == IndexRebuildStatus::InProgress
                    || task.status == IndexRebuildStatus::Completed
            );
        }
    }

    Ok(())
}

#[tokio::test]
async fn test_bulk_sync_indexes_blocks() -> Result<()> {
    let (db, _temp) = setup_db().await?;

    let s = db.session();
    let tx = s.tx().await?;
    let mut bulk = tx
        .bulk_writer()
        .async_indexes(false) // Default behavior
        .batch_size(100)
        .build()?;

    // Insert vertices
    let mut props = Vec::new();
    for i in 0..50 {
        let mut p: HashMap<String, uni_db::Value> = HashMap::new();
        p.insert("name".to_string(), unival!(format!("Person_{}", i)));
        props.push(p);
    }
    bulk.insert_vertices("Person", props).await?;

    let stats = bulk.commit().await?;
    drop(tx);

    // In sync mode, indexes_pending should be false
    assert!(!stats.indexes_pending);
    assert!(stats.index_task_ids.is_empty());

    // Data should be queryable
    let result = db
        .session()
        .query("MATCH (p:Person) RETURN count(p) AS c")
        .await?;
    assert_eq!(result.rows()[0].get::<i64>("c")?, 50);

    Ok(())
}

#[tokio::test]
async fn test_index_rebuild_status_tracking() -> Result<()> {
    let (db, _temp) = setup_db().await?;

    // Initially, there should be no tasks
    let status = db.indexes().rebuild_status().await?;
    // After a fresh DB, status may be empty or have loaded state
    let _initial_count = status.len();

    // Use rebuild_indexes to trigger a task
    let task_id = db.indexes().rebuild("Person", true).await?;

    // If a task was created, verify we can track it
    if let Some(tid) = task_id {
        let status = db.indexes().rebuild_status().await?;
        let found = status.iter().any(|t| t.id == tid);
        assert!(found, "Task {} should be in status list", tid);
    }

    Ok(())
}

#[tokio::test]
async fn test_is_index_building() -> Result<()> {
    let (db, _temp) = setup_db().await?;

    // Initially, no indexes should be building
    let status = db.indexes().rebuild_status().await?;
    let is_building = status.iter().any(|t| {
        matches!(
            t.status,
            uni_store::storage::IndexRebuildStatus::Pending
                | uni_store::storage::IndexRebuildStatus::InProgress
        )
    });
    assert!(!is_building);

    // Trigger an async rebuild
    let _task_id = db.indexes().rebuild("Person", true).await?;

    // Note: The task may complete very quickly for an empty dataset
    // So we just verify the API works without asserting the value

    Ok(())
}

// Schema with NOT NULL constraint for constraint tests
const SCHEMA_WITH_CONSTRAINTS: &str = r#"{
    "schema_version": 1,
    "labels": {
        "Person": {
            "id": 1,
            "created_at": "2024-01-01T00:00:00Z",
            "state": "Active"
        }
    },
    "edge_types": {},
    "properties": {
        "Person": {
            "name": { "type": "String", "nullable": false, "added_in": 1, "state": "Active" },
            "email": { "type": "String", "nullable": true, "added_in": 1, "state": "Active" }
        }
    },
    "constraints": [
        {
            "name": "unique_email",
            "target": { "Label": "Person" },
            "constraint_type": { "Unique": { "properties": ["email"] } },
            "enabled": true
        }
    ],
    "indexes": []
}"#;

async fn setup_db_with_constraints() -> Result<(Uni, tempfile::TempDir)> {
    let temp_dir = tempfile::tempdir()?;
    let path = temp_dir.path();

    let schema_path = path.join("schema.json");
    tokio::fs::write(&schema_path, SCHEMA_WITH_CONSTRAINTS).await?;

    let db = Uni::open(path.to_str().unwrap()).build().await?;
    db.load_schema(&schema_path).await?;

    Ok((db, temp_dir))
}

#[tokio::test]
async fn test_bulk_not_null_constraint() -> Result<()> {
    let (db, _temp) = setup_db_with_constraints().await?;

    let s = db.session();
    let tx = s.tx().await?;
    let mut bulk = tx.bulk_writer().validate_constraints(true).build()?;

    // Try to insert without required "name" field - should fail
    let props = vec![{
        let mut p = HashMap::new();
        // Missing "name" which is NOT NULL
        p.insert("email".to_string(), unival!("test@example.com"));
        p
    }];

    let result = bulk.insert_vertices("Person", props).await;
    assert!(result.is_err(), "Expected NOT NULL constraint violation");
    let err_msg = result.unwrap_err().to_string();
    assert!(
        err_msg.contains("NOT NULL") || err_msg.contains("cannot be null"),
        "Error should mention NOT NULL: {}",
        err_msg
    );

    Ok(())
}

#[tokio::test]
async fn test_bulk_not_null_constraint_with_explicit_null() -> Result<()> {
    let (db, _temp) = setup_db_with_constraints().await?;

    let s = db.session();
    let tx = s.tx().await?;
    let mut bulk = tx.bulk_writer().validate_constraints(true).build()?;

    // Try to insert with explicit null for required field
    let props = vec![{
        let mut p = HashMap::new();
        p.insert("name".to_string(), uni_db::Value::Null); // Explicit null
        p.insert("email".to_string(), unival!("test@example.com"));
        p
    }];

    let result = bulk.insert_vertices("Person", props).await;
    assert!(result.is_err(), "Expected NOT NULL constraint violation");

    Ok(())
}

#[tokio::test]
async fn test_bulk_unique_constraint_in_batch() -> Result<()> {
    let (db, _temp) = setup_db_with_constraints().await?;

    let s = db.session();
    let tx = s.tx().await?;
    let mut bulk = tx.bulk_writer().validate_constraints(true).build()?;

    // Insert batch with duplicate emails - should fail
    let props = vec![
        {
            let mut p = HashMap::new();
            p.insert("name".to_string(), unival!("Alice"));
            p.insert("email".to_string(), unival!("same@example.com"));
            p
        },
        {
            let mut p = HashMap::new();
            p.insert("name".to_string(), unival!("Bob"));
            p.insert("email".to_string(), unival!("same@example.com")); // Duplicate!
            p
        },
    ];

    let result = bulk.insert_vertices("Person", props).await;
    assert!(result.is_err(), "Expected UNIQUE constraint violation");
    let err_msg = result.unwrap_err().to_string();
    assert!(
        err_msg.contains("UNIQUE") || err_msg.contains("duplicate"),
        "Error should mention UNIQUE: {}",
        err_msg
    );

    Ok(())
}

#[tokio::test]
async fn test_bulk_unique_constraint_across_batches() -> Result<()> {
    let (db, _temp) = setup_db_with_constraints().await?;

    let s = db.session();
    let tx = s.tx().await?;
    let mut bulk = tx.bulk_writer().validate_constraints(true).build()?;

    // First batch succeeds
    let props1 = vec![{
        let mut p = HashMap::new();
        p.insert("name".to_string(), unival!("Alice"));
        p.insert("email".to_string(), unival!("alice@example.com"));
        p
    }];
    bulk.insert_vertices("Person", props1).await?;

    // Second batch with same email should fail (conflicts with buffered data)
    let props2 = vec![{
        let mut p = HashMap::new();
        p.insert("name".to_string(), unival!("Bob"));
        p.insert("email".to_string(), unival!("alice@example.com")); // Same as first batch
        p
    }];

    let result = bulk.insert_vertices("Person", props2).await;
    assert!(
        result.is_err(),
        "Expected UNIQUE violation against buffered data"
    );

    Ok(())
}

#[tokio::test]
async fn test_bulk_abort_after_flush_rollback() -> Result<()> {
    let (db, _temp) = setup_db().await?;

    let s = db.session();
    let tx = s.tx().await?;
    let mut bulk = tx.bulk_writer().batch_size(10).build()?; // Small batch to force flush

    // Insert enough data to trigger a flush (batch_size=10)
    let mut props = Vec::new();
    for i in 0..25 {
        let mut p: HashMap<String, uni_db::Value> = HashMap::new();
        p.insert("name".to_string(), unival!(format!("Person_{}", i)));
        p.insert("age".to_string(), unival!(i));
        props.push(p);
    }
    let _vids = bulk.insert_vertices("Person", props).await?;
    // At this point, at least 20 rows should have been flushed to LanceDB

    // Abort the bulk load - should rollback the flushed data via LanceDB version
    bulk.abort().await?;
    drop(tx);

    // Verify no data remains
    let result = db
        .session()
        .query("MATCH (p:Person) RETURN count(p) AS c")
        .await?;
    if result.is_empty() {
        // Dataset was dropped - abort worked correctly
    } else {
        // Dataset exists but should have 0 rows (rollback worked)
        assert_eq!(
            result.rows()[0].get::<i64>("c")?,
            0,
            "Abort should rollback all flushed data"
        );
    }

    Ok(())
}

#[tokio::test]
async fn test_bulk_buffer_limit_checkpoint() -> Result<()> {
    let (db, _temp) = setup_db().await?;

    // Set a very small buffer limit (10KB) and large batch size
    // This forces checkpoint based on buffer size, not batch count
    let s = db.session();
    let tx = s.tx().await?;
    let mut bulk = tx
        .bulk_writer()
        .batch_size(100_000) // Won't flush based on count
        .max_buffer_size_bytes(10 * 1024) // 10KB limit
        .build()?;

    // Insert data that will exceed 10KB when serialized
    // Each vertex with a 500-char name is roughly 500+ bytes
    let mut props = Vec::new();
    for i in 0..100 {
        let mut p: HashMap<String, uni_db::Value> = HashMap::new();
        let long_name = format!("Person_{}_with_a_very_long_name_{}", i, "x".repeat(500));
        p.insert("name".to_string(), unival!(long_name));
        p.insert("age".to_string(), unival!(i));
        props.push(p);
    }

    let vids = bulk.insert_vertices("Person", props).await?;
    assert_eq!(vids.len(), 100);

    // Commit to finalize
    let stats = bulk.commit().await?;
    assert_eq!(stats.vertices_inserted, 100);
    drop(tx);

    // Verify all data was persisted
    let result = db
        .session()
        .query("MATCH (p:Person) RETURN count(p) AS c")
        .await?;
    assert_eq!(result.rows()[0].get::<i64>("c")?, 100);

    Ok(())
}

#[tokio::test]
async fn test_bulk_constraint_validation_disabled() -> Result<()> {
    let (db, _temp) = setup_db_with_constraints().await?;

    // With validation disabled, UNIQUE constraint violations should not fail at insert time
    // Note: Arrow/LanceDB still enforces schema-level nullability, so we can't skip NOT NULL
    let s = db.session();
    let tx = s.tx().await?;
    let mut bulk = tx.bulk_writer().validate_constraints(false).build()?;

    // Insert duplicate emails - should succeed when UNIQUE validation disabled
    let props = vec![
        {
            let mut p = HashMap::new();
            p.insert("name".to_string(), unival!("Alice"));
            p.insert("email".to_string(), unival!("same@example.com"));
            p
        },
        {
            let mut p = HashMap::new();
            p.insert("name".to_string(), unival!("Bob"));
            p.insert("email".to_string(), unival!("same@example.com")); // Duplicate email
            p
        },
    ];

    // This should succeed because UNIQUE validation is disabled
    let result = bulk.insert_vertices("Person", props).await;
    assert!(
        result.is_ok(),
        "Should succeed with validation disabled: {:?}",
        result.err()
    );

    bulk.commit().await?;
    drop(tx);

    // Both rows should exist (constraint was bypassed)
    let result = db
        .session()
        .query("MATCH (p:Person) RETURN count(p) AS c")
        .await?;
    assert_eq!(result.rows()[0].get::<i64>("c")?, 2);

    Ok(())
}