|
1 | 1 | use chrono::DateTime; |
2 | 2 | use common::{ |
3 | 3 | bootstrap_model::index::IndexMetadata, |
4 | | - types::{ |
5 | | - IndexDescriptor, |
6 | | - IndexName, |
7 | | - }, |
| 4 | + types::IndexName, |
8 | 5 | }; |
9 | | -use convex_fivetran_destination::api_types::{ |
10 | | - BatchWriteOperation, |
11 | | - BatchWriteRow, |
12 | | - DeleteType, |
| 6 | +use convex_fivetran_destination::{ |
| 7 | + api_types::{ |
| 8 | + BatchWriteOperation, |
| 9 | + BatchWriteRow, |
| 10 | + DeleteType, |
| 11 | + }, |
| 12 | + constants::{ |
| 13 | + FIVETRAN_PRIMARY_KEY_INDEX_DESCRIPTOR, |
| 14 | + FIVETRAN_SYNCED_INDEX_DESCRIPTOR, |
| 15 | + }, |
13 | 16 | }; |
14 | 17 | use database::{ |
15 | 18 | IndexModel, |
@@ -39,11 +42,14 @@ async fn test_create_new_row(rt: TestRuntime) -> anyhow::Result<()> { |
39 | 42 | let mut tx = application.begin(Identity::system()).await?; |
40 | 43 | let table: TableName = "users".parse()?; |
41 | 44 | IndexModel::new(&mut tx) |
42 | | - .add_application_index( |
| 45 | + .add_system_index( |
43 | 46 | TableNamespace::test_user(), |
44 | 47 | IndexMetadata::new_enabled( |
45 | | - IndexName::new(table.clone(), IndexDescriptor::new("by_primary_key")?)?, |
46 | | - vec![str::parse("id")?, str::parse("_creationTime")?].try_into()?, |
| 48 | + IndexName::new_reserved( |
| 49 | + table.clone(), |
| 50 | + FIVETRAN_PRIMARY_KEY_INDEX_DESCRIPTOR.clone(), |
| 51 | + )?, |
| 52 | + vec!["id".parse()?].try_into()?, |
47 | 53 | ), |
48 | 54 | ) |
49 | 55 | .await?; |
@@ -81,16 +87,14 @@ async fn test_update_row(rt: TestRuntime) -> anyhow::Result<()> { |
81 | 87 | let mut tx = application.begin(Identity::system()).await?; |
82 | 88 | let table: TableName = "posts".parse()?; |
83 | 89 | IndexModel::new(&mut tx) |
84 | | - .add_application_index( |
| 90 | + .add_system_index( |
85 | 91 | TableNamespace::test_user(), |
86 | 92 | IndexMetadata::new_enabled( |
87 | | - IndexName::new(table.clone(), IndexDescriptor::new("by_primary_key")?)?, |
88 | | - vec![ |
89 | | - str::parse("fivetran.deleted")?, |
90 | | - str::parse("fivetran.id")?, |
91 | | - str::parse("_creationTime")?, |
92 | | - ] |
93 | | - .try_into()?, |
| 93 | + IndexName::new_reserved( |
| 94 | + table.clone(), |
| 95 | + FIVETRAN_PRIMARY_KEY_INDEX_DESCRIPTOR.clone(), |
| 96 | + )?, |
| 97 | + vec!["fivetran.deleted".parse()?, "fivetran.id".parse()?].try_into()?, |
94 | 98 | ), |
95 | 99 | ) |
96 | 100 | .await?; |
@@ -171,16 +175,14 @@ async fn test_soft_delete_row(rt: TestRuntime) -> anyhow::Result<()> { |
171 | 175 | let mut tx = application.begin(Identity::system()).await?; |
172 | 176 | let table: TableName = "posts".parse()?; |
173 | 177 | IndexModel::new(&mut tx) |
174 | | - .add_application_index( |
| 178 | + .add_system_index( |
175 | 179 | TableNamespace::test_user(), |
176 | 180 | IndexMetadata::new_enabled( |
177 | | - IndexName::new(table.clone(), IndexDescriptor::new("by_primary_key")?)?, |
178 | | - vec![ |
179 | | - str::parse("fivetran.deleted")?, |
180 | | - str::parse("fivetran.id")?, |
181 | | - str::parse("_creationTime")?, |
182 | | - ] |
183 | | - .try_into()?, |
| 181 | + IndexName::new_reserved( |
| 182 | + table.clone(), |
| 183 | + FIVETRAN_PRIMARY_KEY_INDEX_DESCRIPTOR.clone(), |
| 184 | + )?, |
| 185 | + vec!["fivetran.deleted".parse()?, "fivetran.id".parse()?].try_into()?, |
184 | 186 | ), |
185 | 187 | ) |
186 | 188 | .await?; |
@@ -262,11 +264,14 @@ async fn test_update_missing_row(rt: TestRuntime) -> anyhow::Result<()> { |
262 | 264 | let mut tx = application.begin(Identity::system()).await?; |
263 | 265 | let table: TableName = "posts".parse()?; |
264 | 266 | IndexModel::new(&mut tx) |
265 | | - .add_application_index( |
| 267 | + .add_system_index( |
266 | 268 | TableNamespace::test_user(), |
267 | 269 | IndexMetadata::new_enabled( |
268 | | - IndexName::new(table.clone(), IndexDescriptor::new("by_primary_key")?)?, |
269 | | - vec![str::parse("fivetran.id")?, str::parse("_creationTime")?].try_into()?, |
| 270 | + IndexName::new_reserved( |
| 271 | + table.clone(), |
| 272 | + FIVETRAN_PRIMARY_KEY_INDEX_DESCRIPTOR.clone(), |
| 273 | + )?, |
| 274 | + vec!["fivetran.id".parse()?].try_into()?, |
270 | 275 | ), |
271 | 276 | ) |
272 | 277 | .await?; |
@@ -301,11 +306,14 @@ async fn test_replace_row(rt: TestRuntime) -> anyhow::Result<()> { |
301 | 306 | let mut tx = application.begin(Identity::system()).await?; |
302 | 307 | let table: TableName = "posts".parse()?; |
303 | 308 | IndexModel::new(&mut tx) |
304 | | - .add_application_index( |
| 309 | + .add_system_index( |
305 | 310 | TableNamespace::test_user(), |
306 | 311 | IndexMetadata::new_enabled( |
307 | | - IndexName::new(table.clone(), IndexDescriptor::new("by_primary_key")?)?, |
308 | | - vec![str::parse("id")?, str::parse("_creationTime")?].try_into()?, |
| 312 | + IndexName::new_reserved( |
| 313 | + table.clone(), |
| 314 | + FIVETRAN_PRIMARY_KEY_INDEX_DESCRIPTOR.clone(), |
| 315 | + )?, |
| 316 | + vec!["id".parse()?].try_into()?, |
309 | 317 | ), |
310 | 318 | ) |
311 | 319 | .await?; |
@@ -372,11 +380,14 @@ async fn test_hard_delete_row(rt: TestRuntime) -> anyhow::Result<()> { |
372 | 380 | let mut tx = application.begin(Identity::system()).await?; |
373 | 381 | let table: TableName = "posts".parse()?; |
374 | 382 | IndexModel::new(&mut tx) |
375 | | - .add_application_index( |
| 383 | + .add_system_index( |
376 | 384 | TableNamespace::test_user(), |
377 | 385 | IndexMetadata::new_enabled( |
378 | | - IndexName::new(table.clone(), IndexDescriptor::new("by_primary_key")?)?, |
379 | | - vec![str::parse("id")?, str::parse("_creationTime")?].try_into()?, |
| 386 | + IndexName::new_reserved( |
| 387 | + table.clone(), |
| 388 | + FIVETRAN_PRIMARY_KEY_INDEX_DESCRIPTOR.clone(), |
| 389 | + )?, |
| 390 | + vec!["id".parse()?].try_into()?, |
380 | 391 | ), |
381 | 392 | ) |
382 | 393 | .await?; |
@@ -426,16 +437,14 @@ async fn test_ignores_soft_deleted_rows(rt: TestRuntime) -> anyhow::Result<()> { |
426 | 437 | let mut tx = application.begin(Identity::system()).await?; |
427 | 438 | let table: TableName = "posts".parse()?; |
428 | 439 | IndexModel::new(&mut tx) |
429 | | - .add_application_index( |
| 440 | + .add_system_index( |
430 | 441 | TableNamespace::test_user(), |
431 | 442 | IndexMetadata::new_enabled( |
432 | | - IndexName::new(table.clone(), IndexDescriptor::new("by_primary_key")?)?, |
433 | | - vec![ |
434 | | - str::parse("fivetran.synced")?, |
435 | | - str::parse("id")?, |
436 | | - str::parse("_creationTime")?, |
437 | | - ] |
438 | | - .try_into()?, |
| 443 | + IndexName::new_reserved( |
| 444 | + table.clone(), |
| 445 | + FIVETRAN_PRIMARY_KEY_INDEX_DESCRIPTOR.clone(), |
| 446 | + )?, |
| 447 | + vec!["fivetran.synced".parse()?, "id".parse()?].try_into()?, |
439 | 448 | ), |
440 | 449 | ) |
441 | 450 | .await?; |
@@ -495,11 +504,14 @@ async fn test_batch_of_operations_taking_more_than_one_transaction( |
495 | 504 | let mut tx = application.begin(Identity::system()).await?; |
496 | 505 | let table: TableName = "items".parse()?; |
497 | 506 | IndexModel::new(&mut tx) |
498 | | - .add_application_index( |
| 507 | + .add_system_index( |
499 | 508 | TableNamespace::test_user(), |
500 | 509 | IndexMetadata::new_enabled( |
501 | | - IndexName::new(table.clone(), IndexDescriptor::new("by_primary_key")?)?, |
502 | | - vec![str::parse("id")?, str::parse("_creationTime")?].try_into()?, |
| 510 | + IndexName::new_reserved( |
| 511 | + table.clone(), |
| 512 | + FIVETRAN_PRIMARY_KEY_INDEX_DESCRIPTOR.clone(), |
| 513 | + )?, |
| 514 | + vec!["id".parse()?].try_into()?, |
503 | 515 | ), |
504 | 516 | ) |
505 | 517 | .await?; |
@@ -555,14 +567,14 @@ async fn test_soft_truncate_all(rt: TestRuntime) -> anyhow::Result<()> { |
555 | 567 | let mut tx = application.begin(Identity::system()).await?; |
556 | 568 | let table: TableName = "table".parse()?; |
557 | 569 | IndexModel::new(&mut tx) |
558 | | - .add_application_index( |
| 570 | + .add_system_index( |
559 | 571 | TableNamespace::test_user(), |
560 | 572 | IndexMetadata::new_enabled( |
561 | | - IndexName::new(table.clone(), IndexDescriptor::new("my_sync_index")?)?, |
| 573 | + IndexName::new_reserved(table.clone(), FIVETRAN_SYNCED_INDEX_DESCRIPTOR.clone())?, |
562 | 574 | vec![ |
563 | | - str::parse("fivetran.deleted")?, |
564 | | - str::parse("fivetran.synced")?, |
565 | | - str::parse("_creationTime")?, |
| 575 | + "fivetran.deleted".parse()?, |
| 576 | + "fivetran.synced".parse()?, |
| 577 | + "_creationTime".parse()?, |
566 | 578 | ] |
567 | 579 | .try_into()?, |
568 | 580 | ), |
@@ -621,14 +633,14 @@ async fn test_hard_truncate_since_timestamp(rt: TestRuntime) -> anyhow::Result<( |
621 | 633 | let mut tx = application.begin(Identity::system()).await?; |
622 | 634 | let table: TableName = "table".parse()?; |
623 | 635 | IndexModel::new(&mut tx) |
624 | | - .add_application_index( |
| 636 | + .add_system_index( |
625 | 637 | TableNamespace::test_user(), |
626 | 638 | IndexMetadata::new_enabled( |
627 | | - IndexName::new(table.clone(), IndexDescriptor::new("my_sync_index")?)?, |
| 639 | + IndexName::new_reserved(table.clone(), FIVETRAN_SYNCED_INDEX_DESCRIPTOR.clone())?, |
628 | 640 | vec![ |
629 | | - str::parse("fivetran.deleted")?, |
630 | | - str::parse("fivetran.synced")?, |
631 | | - str::parse("_creationTime")?, |
| 641 | + "fivetran.deleted".parse()?, |
| 642 | + "fivetran.synced".parse()?, |
| 643 | + "_creationTime".parse()?, |
632 | 644 | ] |
633 | 645 | .try_into()?, |
634 | 646 | ), |
@@ -680,14 +692,14 @@ async fn test_soft_truncate_since_timestamp(rt: TestRuntime) -> anyhow::Result<( |
680 | 692 | let mut tx = application.begin(Identity::system()).await?; |
681 | 693 | let table: TableName = "table".parse()?; |
682 | 694 | IndexModel::new(&mut tx) |
683 | | - .add_application_index( |
| 695 | + .add_system_index( |
684 | 696 | TableNamespace::test_user(), |
685 | 697 | IndexMetadata::new_enabled( |
686 | | - IndexName::new(table.clone(), IndexDescriptor::new("my_sync_index")?)?, |
| 698 | + IndexName::new_reserved(table.clone(), FIVETRAN_SYNCED_INDEX_DESCRIPTOR.clone())?, |
687 | 699 | vec![ |
688 | | - str::parse("fivetran.deleted")?, |
689 | | - str::parse("fivetran.synced")?, |
690 | | - str::parse("_creationTime")?, |
| 700 | + "fivetran.deleted".parse()?, |
| 701 | + "fivetran.synced".parse()?, |
| 702 | + "_creationTime".parse()?, |
691 | 703 | ] |
692 | 704 | .try_into()?, |
693 | 705 | ), |
@@ -783,14 +795,14 @@ async fn test_soft_truncate_larger_than_one_transaction(rt: TestRuntime) -> anyh |
783 | 795 | let mut tx = application.begin(Identity::system()).await?; |
784 | 796 | let table: TableName = "table".parse()?; |
785 | 797 | IndexModel::new(&mut tx) |
786 | | - .add_application_index( |
| 798 | + .add_system_index( |
787 | 799 | TableNamespace::test_user(), |
788 | 800 | IndexMetadata::new_enabled( |
789 | | - IndexName::new(table.clone(), IndexDescriptor::new("my_sync_index")?)?, |
| 801 | + IndexName::new_reserved(table.clone(), FIVETRAN_SYNCED_INDEX_DESCRIPTOR.clone())?, |
790 | 802 | vec![ |
791 | | - str::parse("fivetran.deleted")?, |
792 | | - str::parse("fivetran.synced")?, |
793 | | - str::parse("_creationTime")?, |
| 803 | + "fivetran.deleted".parse()?, |
| 804 | + "fivetran.synced".parse()?, |
| 805 | + "_creationTime".parse()?, |
794 | 806 | ] |
795 | 807 | .try_into()?, |
796 | 808 | ), |
@@ -846,14 +858,14 @@ async fn test_hard_truncate_larger_than_one_transaction(rt: TestRuntime) -> anyh |
846 | 858 | let mut tx = application.begin(Identity::system()).await?; |
847 | 859 | let table: TableName = "table".parse()?; |
848 | 860 | IndexModel::new(&mut tx) |
849 | | - .add_application_index( |
| 861 | + .add_system_index( |
850 | 862 | TableNamespace::test_user(), |
851 | 863 | IndexMetadata::new_enabled( |
852 | | - IndexName::new(table.clone(), IndexDescriptor::new("my_sync_index")?)?, |
| 864 | + IndexName::new_reserved(table.clone(), FIVETRAN_SYNCED_INDEX_DESCRIPTOR.clone())?, |
853 | 865 | vec![ |
854 | | - str::parse("fivetran.deleted")?, |
855 | | - str::parse("fivetran.synced")?, |
856 | | - str::parse("_creationTime")?, |
| 866 | + "fivetran.deleted".parse()?, |
| 867 | + "fivetran.synced".parse()?, |
| 868 | + "_creationTime".parse()?, |
857 | 869 | ] |
858 | 870 | .try_into()?, |
859 | 871 | ), |
|
0 commit comments