diff --git a/docs/documents/indexing/computed-indexes.md b/docs/documents/indexing/computed-indexes.md
index cf8f3ac00e..64cd345c86 100644
--- a/docs/documents/indexing/computed-indexes.md
+++ b/docs/documents/indexing/computed-indexes.md
@@ -34,7 +34,7 @@ using (var session = store.QuerySession())
.FirstOrDefault(x => x.UserName == "somebody");
}
```
-snippet source | anchor
+snippet source | anchor
In the configuration shown above, Marten generates a database index in Postgresql:
@@ -55,7 +55,7 @@ var store = DocumentStore.For(_ =>
_.Schema.For().Index(x => x.Inner.Color);
});
```
-snippet source | anchor
+snippet source | anchor
The configuration above creates an index like this:
@@ -139,5 +139,5 @@ var store = DocumentStore.For(_ =>
});
});
```
-snippet source | anchor
+snippet source | anchor
diff --git a/docs/documents/indexing/unique.md b/docs/documents/indexing/unique.md
index 0993a4ab19..976dc7aa6e 100644
--- a/docs/documents/indexing/unique.md
+++ b/docs/documents/indexing/unique.md
@@ -225,7 +225,7 @@ var store = DocumentStore.For(_ =>
});
});
```
-snippet source | anchor
+snippet source | anchor
Same can be configured for Duplicated Field:
diff --git a/docs/documents/querying/sql.md b/docs/documents/querying/sql.md
index 67062ab442..7989efd5d1 100644
--- a/docs/documents/querying/sql.md
+++ b/docs/documents/querying/sql.md
@@ -50,7 +50,7 @@ a document body, but in that case you will need to supply the full SQL statement
var sumResults = await session
.QueryAsync("select count(*) from mt_doc_target");
```
-snippet source | anchor
+snippet source | anchor
When querying single JSONB properties into a primitive/value type, you'll need to cast the value to the respective postgres type:
diff --git a/src/DocumentDbTests/Indexes/computed_indexes.cs b/src/DocumentDbTests/Indexes/computed_indexes.cs
index e5c83a1cb2..7299664874 100644
--- a/src/DocumentDbTests/Indexes/computed_indexes.cs
+++ b/src/DocumentDbTests/Indexes/computed_indexes.cs
@@ -8,6 +8,7 @@
using Marten.Testing.Documents;
using Marten.Testing.Harness;
using Shouldly;
+using Weasel.Core;
using Weasel.Postgresql.Tables;
using Xunit;
@@ -167,23 +168,36 @@ public async Task create_multi_property_string_index_with_casing()
var index = table.IndexFor("mt_doc_target_idx_stringstring_field");
index.ToDDL(table).ShouldBe("CREATE INDEX mt_doc_target_idx_stringstring_field ON computed_indexes.mt_doc_target USING btree (upper((data ->> 'String'), upper((data ->> 'StringField'))));");
-
-
}
[Fact]
- public void creating_index_using_date_should_work()
+ public async Task creating_index_using_date_should_work()
{
StoreOptions(_ =>
{
- _.Schema.For().Index(x => x.Date);
+ _.Schema.For().Index(x => x.RequestTimeUtc);
+ _.AutoCreateSchemaObjects = AutoCreate.All;
});
+ var diff = await theStore.Storage.Database.ApplyAllConfiguredChangesToDatabaseAsync(AutoCreate.CreateOrUpdate);
- var data = Target.GenerateRandomData(100).ToArray();
- theStore.BulkInsert(data.ToArray());
+ diff.ShouldBe(SchemaPatchDifference.Create);
- }
+ var table = await theStore.Tenancy.Default.Database.ExistingTableFor(typeof(ApiResponseRecord));
+ var index = table.IndexFor("mt_doc_apiresponserecord_idx_request_time_utc");
+
+ index.ShouldNotBeNull();
+
+ index.ToDDL(table).ShouldBe("CREATE INDEX mt_doc_apiresponserecord_idx_request_time_utc ON computed_indexes.mt_doc_apiresponserecord USING btree (computed_indexes.mt_immutable_timestamp((data ->> 'RequestTimeUtc')));");
+ using var otherStore = SeparateStore(_ =>
+ {
+ _.Schema.For().Index(x => x.RequestTimeUtc);
+ _.AutoCreateSchemaObjects = AutoCreate.All;
+ });
+
+ var diff2 = await otherStore.Storage.Database.ApplyAllConfiguredChangesToDatabaseAsync(AutoCreate.CreateOrUpdate);
+ diff2.ShouldBe(SchemaPatchDifference.None);
+ }
[Fact]
public async Task create_index_with_custom_name()
@@ -277,7 +291,13 @@ public async Task create_multi_index_including_collection()
var index = table.IndexFor("mt_doc_target_idx_user_idstring_list");
index.ToDDL(table).ShouldBe("CREATE INDEX mt_doc_target_idx_user_idstring_list ON computed_indexes.mt_doc_target USING btree (CAST(data ->> 'UserId' as uuid), CAST(data ->> 'StringList' as jsonb));");
-
}
+}
-}
\ No newline at end of file
+public class ApiResponseRecord
+{
+ public Guid Id { get; set; }
+ public string Request { get; set; }
+ public string Response { get; set; }
+ public DateTime RequestTimeUtc { get; set; }
+}