Skip to content

Commit

Permalink
Create temp table for bulk loading with "LIKE" clause
Browse files Browse the repository at this point in the history
Using "LIKE" and "INCLUDING DEFAULTS" is required to
e.g. set mt_deleted to the default falue FALSE, otherwise
it will be set to NULL.
  • Loading branch information
e-tobi authored and jeremydmiller committed Jul 26, 2024
1 parent b01ee81 commit e2e27af
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/DocumentDbTests/Writing/bulk_loading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,24 @@ public async Task can_bulk_insert_mixed_list_of_objects_enlist_transaction_async
}
}

[Fact]
public async Task can_bulk_insert_soft_deletable_documents_when_using_overwrite_mode()
{
StoreOptions(x => x.Schema.For<User>().SoftDeletedWithIndex());

var doc1 = new User();
var doc2 = new User();

var documents = new object[] { doc1, doc2 };

await theStore.BulkInsertAsync(documents, BulkInsertMode.OverwriteExisting);

await using (var querying = theStore.QuerySession())
{
querying.Query<User>().Count().ShouldBe(2);
}
}

public Task InitializeAsync()
{
return theStore.Advanced.Clean.DeleteAllDocumentsAsync();
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Internal/CodeGeneration/BulkLoaderBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ public string OverwriteDuplicatesFromTempTable()

public string CreateTempTableForCopying()
{
return $"create temporary table {_tempTable} as select * from {_mapping.TableName.QualifiedName} limit 0";
return $"create temporary table {_tempTable} (like {_mapping.TableName.QualifiedName} including defaults)";
}
}

0 comments on commit e2e27af

Please sign in to comment.