Skip to content

Commit

Permalink
Renamed CreatedTimestamp column to CreatedAt. This aligns the naming …
Browse files Browse the repository at this point in the history
…with other columns like DeletedAt.

Fixed failing created column queries tests by using OneOffConfiguration base class to not interfer with other tests.
  • Loading branch information
oskardudycz committed Oct 23, 2023
1 parent 1938b8d commit d235056
Show file tree
Hide file tree
Showing 20 changed files with 68 additions and 53 deletions.
6 changes: 3 additions & 3 deletions src/DocumentDbTests/Configuration/MartenRegistryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public MartenRegistryTests()
})
.GinIndexJsonData(x => x.Name = "my_gin_index")
.IndexLastModified(x => x.IsConcurrent = true)
.IndexCreatedTimestamp(x => x.IsConcurrent = true)
.IndexCreatedAt(x => x.IsConcurrent = true)
.SoftDeletedWithIndex(x => x.Method = IndexMethod.brin);

_.Schema.For<User>().PropertySearching(PropertySearching.JSON_Locator_Only);
Expand Down Expand Up @@ -110,11 +110,11 @@ public void mt_last_modified_index_is_added()
}

[Fact]
public void mt_created_index_is_added()
public void mt_created_at_index_is_added()
{
var mapping = theStorage.MappingFor(typeof(Organization)).As<DocumentMapping>();

var index = mapping.IndexesFor(SchemaConstants.CreatedTimestampColumn).Single();
var index = mapping.IndexesFor(SchemaConstants.CreatedAtColumn).Single();

index.IsConcurrent.ShouldBe(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void document_policy_for_metadata_defaults()

theStore.StorageFeatures.MappingFor(typeof(UserMetadata)).Metadata.Version.Enabled.ShouldBeTrue();
theStore.StorageFeatures.MappingFor(typeof(UserMetadata)).Metadata.LastModified.Enabled.ShouldBeTrue();
theStore.StorageFeatures.MappingFor(typeof(UserMetadata)).Metadata.CreatedTimestamp.Enabled.ShouldBeFalse();
theStore.StorageFeatures.MappingFor(typeof(UserMetadata)).Metadata.CreatedAt.Enabled.ShouldBeFalse();
theStore.StorageFeatures.MappingFor(typeof(UserMetadata)).Metadata.TenantId.Enabled.ShouldBeTrue();
theStore.StorageFeatures.MappingFor(typeof(UserMetadata)).Metadata.IsSoftDeleted.Enabled.ShouldBeTrue();
theStore.StorageFeatures.MappingFor(typeof(UserMetadata)).Metadata.SoftDeletedAt.Enabled.ShouldBeTrue();
Expand All @@ -43,7 +43,7 @@ public void document_policy_for_metadata_all_enabled()
{
_.Policies.ForAllDocuments(x => x.Metadata.Version.Enabled = true);
_.Policies.ForAllDocuments(x => x.Metadata.LastModified.Enabled = true);
_.Policies.ForAllDocuments(x => x.Metadata.CreatedTimestamp.Enabled = true);
_.Policies.ForAllDocuments(x => x.Metadata.CreatedAt.Enabled = true);
_.Policies.ForAllDocuments(x => x.Metadata.TenantId.Enabled = true);
_.Policies.ForAllDocuments(x => x.Metadata.IsSoftDeleted.Enabled = true);
_.Policies.ForAllDocuments(x => x.Metadata.SoftDeletedAt.Enabled = true);
Expand All @@ -57,7 +57,7 @@ public void document_policy_for_metadata_all_enabled()

theStore.StorageFeatures.MappingFor(typeof(UserMetadata)).Metadata.Version.Enabled.ShouldBeTrue();
theStore.StorageFeatures.MappingFor(typeof(UserMetadata)).Metadata.LastModified.Enabled.ShouldBeTrue();
theStore.StorageFeatures.MappingFor(typeof(UserMetadata)).Metadata.CreatedTimestamp.Enabled.ShouldBeTrue();
theStore.StorageFeatures.MappingFor(typeof(UserMetadata)).Metadata.CreatedAt.Enabled.ShouldBeTrue();
theStore.StorageFeatures.MappingFor(typeof(UserMetadata)).Metadata.TenantId.Enabled.ShouldBeTrue();
theStore.StorageFeatures.MappingFor(typeof(UserMetadata)).Metadata.IsSoftDeleted.Enabled.ShouldBeTrue();
theStore.StorageFeatures.MappingFor(typeof(UserMetadata)).Metadata.SoftDeletedAt.Enabled.ShouldBeTrue();
Expand All @@ -76,7 +76,7 @@ public void document_policy_for_metadata_all_disabled()
{
_.Policies.ForAllDocuments(x => x.Metadata.Version.Enabled = false);
_.Policies.ForAllDocuments(x => x.Metadata.LastModified.Enabled = false);
_.Policies.ForAllDocuments(x => x.Metadata.CreatedTimestamp.Enabled = false);
_.Policies.ForAllDocuments(x => x.Metadata.CreatedAt.Enabled = false);
_.Policies.ForAllDocuments(x => x.Metadata.TenantId.Enabled = false);
_.Policies.ForAllDocuments(x => x.Metadata.IsSoftDeleted.Enabled = false);
_.Policies.ForAllDocuments(x => x.Metadata.SoftDeletedAt.Enabled = false);
Expand All @@ -90,7 +90,7 @@ public void document_policy_for_metadata_all_disabled()

theStore.StorageFeatures.MappingFor(typeof(UserMetadata)).Metadata.Version.Enabled.ShouldBeFalse();
theStore.StorageFeatures.MappingFor(typeof(UserMetadata)).Metadata.LastModified.Enabled.ShouldBeFalse();
theStore.StorageFeatures.MappingFor(typeof(UserMetadata)).Metadata.CreatedTimestamp.Enabled.ShouldBeFalse();
theStore.StorageFeatures.MappingFor(typeof(UserMetadata)).Metadata.CreatedAt.Enabled.ShouldBeFalse();
theStore.StorageFeatures.MappingFor(typeof(UserMetadata)).Metadata.TenantId.Enabled.ShouldBeFalse();
theStore.StorageFeatures.MappingFor(typeof(UserMetadata)).Metadata.IsSoftDeleted.Enabled.ShouldBeFalse();
theStore.StorageFeatures.MappingFor(typeof(UserMetadata)).Metadata.SoftDeletedAt.Enabled.ShouldBeFalse();
Expand Down
25 changes: 15 additions & 10 deletions src/DocumentDbTests/Metadata/created_timestamp_queries.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
using Marten;
using Marten.Linq.CreatedTimestamp;
using Marten.Schema;
using Marten.Testing.Documents;
using Marten.Testing.Harness;
using Shouldly;
using System.Linq;
using Marten.Linq.CreatedAt;
using Weasel.Postgresql.Tables;
using Xunit;

namespace DocumentDbTests.Metadata;

public class created_timestamp_queries: IntegrationContext
public class created_timestamp_queries: OneOffConfigurationsContext
{
[Fact]
public void creates_btree_index_for_mt_created()
public void creates_btree_index_for_mt_created_at()
{
var mapping = DocumentMapping.For<Customer>();
var indexDefinition = mapping.Indexes.Cast<DocumentIndex>().Single(x => x.Columns.First() == SchemaConstants.CreatedTimestampColumn);
var indexDefinition = mapping.Indexes.Cast<DocumentIndex>().Single(x => x.Columns.First() == SchemaConstants.CreatedAtColumn);

indexDefinition.Method.ShouldBe(IndexMethod.btree);
}

#region sample_index-created-timestamp-via-attribute
[IndexedCreatedTimestamp]
[IndexedCreatedAt]
public class Customer
{
}
Expand All @@ -44,7 +43,10 @@ public void query_created_before_docs()
session.Store(user3, user4);
session.SaveChanges();

var epoch = session.MetadataFor(user4).CreatedTimestamp;
var metadata = session.MetadataFor(user4);
metadata.ShouldNotBeNull();

var epoch = metadata.CreatedAt;

// no where clause
session.Query<User>()
Expand Down Expand Up @@ -74,7 +76,10 @@ public void query_created_since_docs()
session.Store(user1, user2);
session.SaveChanges();

var epoch = session.MetadataFor(user2).CreatedTimestamp;
var metadata = session.MetadataFor(user2);
metadata.ShouldNotBeNull();

var epoch = metadata.CreatedAt;
session.Store(user3, user4);
session.SaveChanges();

Expand All @@ -95,8 +100,8 @@ public void query_created_since_docs()
.ShouldBe("jack");
}

public created_timestamp_queries(DefaultStoreFixture fixture) : base(fixture)
public created_timestamp_queries()
{
fixture.Store.Options.Policies.ForAllDocuments(o => o.Metadata.CreatedTimestamp.Enabled = true);
StoreOptions(options => options.Policies.ForAllDocuments(o => o.Metadata.CreatedAt.Enabled = true));
}
}
16 changes: 10 additions & 6 deletions src/DocumentDbTests/Metadata/fetching_entity_metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public void hit_returns_values()

metadata.ShouldNotBeNull();
metadata.CurrentVersion.ShouldNotBe(Guid.Empty);
metadata.CreatedAt.ShouldBe(default);
metadata.LastModified.ShouldNotBe(default);
metadata.DotNetType.ShouldBe(typeof(CoffeeShop).FullName);
metadata.DocumentType.ShouldBeNull();
Expand Down Expand Up @@ -71,6 +72,7 @@ public async Task hit_returns_values_async()

metadata.ShouldNotBeNull();
metadata.CurrentVersion.ShouldNotBe(Guid.Empty);
metadata.CreatedAt.ShouldBe(default);
metadata.LastModified.ShouldNotBe(default);
metadata.DotNetType.ShouldBe(typeof(CoffeeShop).FullName);
metadata.DocumentType.ShouldBe("coffee_shop");
Expand All @@ -92,8 +94,9 @@ public void created_timestamp_metadata_returns_default()
using (var session = theStore.QuerySession())
{
var metadata = session.MetadataFor(shop);
metadata.ShouldNotBeNull();

metadata.CreatedTimestamp.ShouldBe(default);
metadata.CreatedAt.ShouldBe(default);
}
}

Expand All @@ -111,15 +114,15 @@ public async Task created_timestamp_metadata_returns_default_async()
await using var query = theStore.QuerySession();
var metadata = await query.MetadataForAsync(shop);

metadata.CreatedTimestamp.ShouldBe(default);
metadata.CreatedAt.ShouldBe(default);
}

[Fact]
public void created_timestamp_metadata_returns_timestamp()
{
StoreOptions(_ =>
{
_.Policies.ForAllDocuments(o => o.Metadata.CreatedTimestamp.Enabled = true);
_.Policies.ForAllDocuments(o => o.Metadata.CreatedAt.Enabled = true);
});

var shop = new CoffeeShop();
Expand All @@ -133,8 +136,9 @@ public void created_timestamp_metadata_returns_timestamp()
using (var session = theStore.QuerySession())
{
var metadata = session.MetadataFor(shop);
metadata.ShouldNotBeNull();

metadata.CreatedTimestamp.ShouldNotBeNull();
metadata.CreatedAt.ShouldNotBeNull();
}
}

Expand All @@ -143,7 +147,7 @@ public async Task created_timestamp_metadata_returns_timestamp_async()
{
StoreOptions(_ =>
{
_.Policies.ForAllDocuments(o => o.Metadata.CreatedTimestamp.Enabled = true);
_.Policies.ForAllDocuments(o => o.Metadata.CreatedAt.Enabled = true);
});

var shop = new CoffeeShop();
Expand All @@ -157,6 +161,6 @@ public async Task created_timestamp_metadata_returns_timestamp_async()
await using var query = theStore.QuerySession();
var metadata = await query.MetadataForAsync(shop);

metadata.CreatedTimestamp.ShouldNotBeNull();
metadata.CreatedAt.ShouldNotBeNull();
}
}
10 changes: 8 additions & 2 deletions src/DocumentDbTests/Metadata/last_modified_queries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ public void query_modified_since_docs()
session.Store(user1, user2, user3, user4);
session.SaveChanges();

var epoch = session.MetadataFor(user4).LastModified;
var metadata = session.MetadataFor(user4);
metadata.ShouldNotBeNull();

var epoch = metadata.LastModified;
session.Store(user3, user4);
session.SaveChanges();

Expand Down Expand Up @@ -92,7 +95,10 @@ public void query_modified_before_docs()
session.Store(user3, user4);
session.SaveChanges();

var epoch = session.MetadataFor(user4).LastModified;
var metadata = session.MetadataFor(user4);
metadata.ShouldNotBeNull();

var epoch = metadata.LastModified;

// no where clause
session.Query<User>().Where(x => x.ModifiedBefore(epoch)).OrderBy(x => x.UserName).Select(x => x.UserName)
Expand Down
2 changes: 1 addition & 1 deletion src/Marten.Testing/Examples/MartenRegistryExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public MartenRegistryExamples()
#region sample_index-created-timestamp-via-fi
DocumentStore.For(_ =>
{
_.Schema.For<User>().IndexCreatedTimestamp();
_.Schema.For<User>().IndexCreatedAt();
});
#endregion
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#nullable enable
using System;

namespace Marten.Linq.CreatedTimestamp;
namespace Marten.Linq.CreatedAt;

public static class CreatedTimestampExtensions
public static class CreatedAtExtensions
{
/// <summary>
/// The search results should include documents created since given time (&gt;)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
using Marten.Schema;
using Weasel.Postgresql.SqlGeneration;

namespace Marten.Linq.CreatedTimestamp;
namespace Marten.Linq.CreatedAt;

public class CreatedBeforeParser: IMethodCallParser
{
private static readonly MethodInfo _method =
typeof(CreatedTimestampExtensions).GetMethod(nameof(CreatedTimestampExtensions.CreatedBefore));
typeof(CreatedAtExtensions).GetMethod(nameof(CreatedAtExtensions.CreatedBefore));

public bool Matches(MethodCallExpression expression)
{
Expand All @@ -24,6 +24,6 @@ public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options,
{
var time = expression.Arguments.Last().Value().As<DateTimeOffset>();

return new WhereFragment($"d.{SchemaConstants.CreatedTimestampColumn} < ?", time);
return new WhereFragment($"d.{SchemaConstants.CreatedAtColumn} < ?", time);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
using Marten.Schema;
using Weasel.Postgresql.SqlGeneration;

namespace Marten.Linq.CreatedTimestamp;
namespace Marten.Linq.CreatedAt;

public class CreatedSinceParser: IMethodCallParser
{
private static readonly MethodInfo _method =
typeof(CreatedTimestampExtensions).GetMethod(nameof(CreatedTimestampExtensions.CreatedSince));
typeof(CreatedAtExtensions).GetMethod(nameof(CreatedAtExtensions.CreatedSince));

public bool Matches(MethodCallExpression expression)
{
Expand All @@ -24,6 +24,6 @@ public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options,
{
var time = expression.Arguments.Last().Value().As<DateTimeOffset>();

return new WhereFragment($"d.{SchemaConstants.CreatedTimestampColumn} > ?", time);
return new WhereFragment($"d.{SchemaConstants.CreatedAtColumn} > ?", time);
}
}
2 changes: 1 addition & 1 deletion src/Marten/LinqParsing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Linq.Expressions;
using JasperFx.Core;
using Marten.Events.Archiving;
using Marten.Linq.CreatedTimestamp;
using Marten.Linq.CreatedAt;
using Marten.Linq.Fields;
using Marten.Linq.LastModified;
using Marten.Linq.MatchesSql;
Expand Down
6 changes: 3 additions & 3 deletions src/Marten/MartenRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ public DocumentMappingExpression<T> IndexLastModified(Action<DocumentIndex>? con
/// </summary>
/// <param name="configure"></param>
/// <returns></returns>
public DocumentMappingExpression<T> IndexCreatedTimestamp(Action<DocumentIndex>? configure = null)
public DocumentMappingExpression<T> IndexCreatedAt(Action<DocumentIndex>? configure = null)
{
_builder.Alter = m => m.AddCreatedTimestampIndex(configure);
_builder.Alter = m => m.AddCreatedAtIndex(configure);

return this;
}
Expand Down Expand Up @@ -706,7 +706,7 @@ public MetadataConfig(DocumentMappingExpression<T> parent)
/// <summary>
/// Optional metadata for the timestamp of when this document was created
/// </summary>
public Column<string> CreatedTimestamp => new(_parent, m => m.CreatedTimestamp);
public Column<string> CreatedAt => new(_parent, m => m.CreatedAt);

/// <summary>
/// The stored tenant id of this document
Expand Down
4 changes: 2 additions & 2 deletions src/Marten/Schema/DocumentMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,9 @@ public DocumentIndex AddLastModifiedIndex(Action<DocumentIndex> configure = null
return index;
}

public DocumentIndex AddCreatedTimestampIndex(Action<DocumentIndex> configure = null)
public DocumentIndex AddCreatedAtIndex(Action<DocumentIndex> configure = null)
{
var index = new DocumentIndex(this, SchemaConstants.CreatedTimestampColumn);
var index = new DocumentIndex(this, SchemaConstants.CreatedAtColumn);
configure?.Invoke(index);
Indexes.Add(index);

Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Schema/DocumentMetadataCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public DocumentMetadataCollection(DocumentMapping parent)

public MetadataColumn Version { get; } = new VersionColumn();
public MetadataColumn LastModified { get; } = new LastModifiedColumn();
public MetadataColumn CreatedTimestamp { get; } = new CreatedTimestampColumn();
public MetadataColumn CreatedAt { get; } = new CreatedAtColumn();
public MetadataColumn TenantId { get; } = new TenantIdColumn();
public MetadataColumn IsSoftDeleted { get; } = new SoftDeletedColumn();
public MetadataColumn SoftDeletedAt { get; } = new DeletedAtColumn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace Marten.Schema;
/// Creates an index on the predefined Last Modified column
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class IndexedCreatedTimestampAttribute: MartenAttribute
public class IndexedCreatedAtAttribute: MartenAttribute
{
public override void Modify(DocumentMapping mapping)
{
mapping.AddCreatedTimestampIndex();
mapping.AddCreatedAtIndex();
}
}
4 changes: 2 additions & 2 deletions src/Marten/Schema/MetadataAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public override void Modify(DocumentMapping mapping, MemberInfo member)
/// Direct Marten to copy the created timestamp metadata to this member
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class CreatedTimestampMetadataAttribute: MartenAttribute
public class CreatedAtMetadataAttribute: MartenAttribute
{
public override void Modify(DocumentMapping mapping, MemberInfo member)
{
mapping.Metadata.CreatedTimestamp.Member = member;
mapping.Metadata.CreatedAt.Member = member;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Schema/SchemaConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class SchemaConstants
public const string LastModifiedColumn = "mt_last_modified";
public const string DotNetTypeColumn = "mt_dotnet_type";
public const string VersionColumn = "mt_version";
public const string CreatedTimestampColumn = "mt_created";
public const string CreatedAtColumn = "mt_created_at";
public const string DeletedColumn = "mt_deleted";
public const string DeletedAtColumn = "mt_deleted_at";

Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Storage/DocumentTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public DocumentTable(DocumentMapping mapping): base(mapping.TableName)
AddIfActive(_mapping.Metadata.LastModified);
AddIfActive(_mapping.Metadata.Version);
AddIfActive(_mapping.Metadata.DotNetType);
AddIfActive(_mapping.Metadata.CreatedTimestamp);
AddIfActive(_mapping.Metadata.CreatedAt);

AddIfActive(_mapping.Metadata.CorrelationId);
AddIfActive(_mapping.Metadata.CausationId);
Expand Down
Loading

0 comments on commit d235056

Please sign in to comment.