diff --git a/docs/configuration/multitenancy.md b/docs/configuration/multitenancy.md
index 355e42fc67..a2cd616b95 100644
--- a/docs/configuration/multitenancy.md
+++ b/docs/configuration/multitenancy.md
@@ -101,7 +101,7 @@ If you don't know the tenant upfront, you can create and apply changes dynamical
var tenant = await theStore.Tenancy.GetTenantAsync(tenantId);
await tenant.Database.ApplyAllConfiguredChangesToDatabaseAsync();
```
-snippet source | anchor
+snippet source | anchor
You can place this code somewhere in the tenant initialization code. For instance:
diff --git a/docs/scenarios/using-sequence-for-unique-id.md b/docs/scenarios/using-sequence-for-unique-id.md
index e35d6a1387..b442552cb1 100644
--- a/docs/scenarios/using-sequence-for-unique-id.md
+++ b/docs/scenarios/using-sequence-for-unique-id.md
@@ -17,7 +17,7 @@ public class MatterId: FeatureSchemaBase
private readonly int _startFrom;
private readonly string _schema;
- public MatterId(StoreOptions options, int startFrom) : base(nameof(MatterId), options.Advanced.Migrator)
+ public MatterId(StoreOptions options, int startFrom): base(nameof(MatterId), options.Advanced.Migrator)
{
_startFrom = startFrom;
_schema = options.DatabaseSchemaName;
@@ -26,11 +26,12 @@ public class MatterId: FeatureSchemaBase
protected override IEnumerable schemaObjects()
{
// We return a sequence that starts from the value provided in the ctor
- yield return new Sequence(new DbObjectName(_schema, $"mt_{nameof(MatterId).ToLowerInvariant()}"), _startFrom);
+ yield return new Sequence(new PostgresqlObjectName(_schema, $"mt_{nameof(MatterId).ToLowerInvariant()}"),
+ _startFrom);
}
}
```
-snippet source | anchor
+snippet source | anchor
This sequence yielding customization will be plugged into Marten via the store configuration
@@ -40,7 +41,7 @@ This sequence yielding customization will be plugged into Marten via the store c
```cs
storeOptions.Storage.Add(new MatterId(storeOptions, 10000));
```
-snippet source | anchor
+snippet source | anchor
and then executed against the database (generating & executing the DDL statements that create the required database objects):
@@ -50,7 +51,7 @@ and then executed against the database (generating & executing the DDL statement
```cs
await theStore.Storage.ApplyAllConfiguredChangesToDatabaseAsync();
```
-snippet source | anchor
+snippet source | anchor
We introduce a few types with `Guid` identifiers, whom we reference to our end users by numbers, encapsulated in the `Matter` field:
@@ -61,17 +62,20 @@ We introduce a few types with `Guid` identifiers, whom we reference to our end u
public class Contract
{
public Guid Id { get; set; }
+
public int Matter { get; set; }
// Other fields...
}
+
public class Inquiry
{
public Guid Id { get; set; }
+
public int Matter { get; set; }
// Other fields...
}
```
-snippet source | anchor
+snippet source | anchor
Now, when creating and persisting such types, we first query the database for a new and unique running number. While we generate (or if wanted, let Marten generate) non-human-readable, system-internal identifiers for the created instances, we assign to them the newly generated and unique human-readable identifier:
@@ -85,24 +89,16 @@ await using var session = theStore.LightweightSession();
// Generate a new, unique identifier
var nextMatter = session.NextInSequence(matter);
-var contract = new Contract
-{
- Id = Guid.NewGuid(),
- Matter = nextMatter
-};
+var contract = new Contract { Id = Guid.NewGuid(), Matter = nextMatter };
-var inquiry = new Inquiry
-{
- Id = Guid.NewGuid(),
- Matter = nextMatter
-};
+var inquiry = new Inquiry { Id = Guid.NewGuid(), Matter = nextMatter };
session.Store(contract);
session.Store(inquiry);
await session.SaveChangesAsync();
```
-snippet source | anchor
+snippet source | anchor
Lastly, we have an extension method (used above) as a shorthand for generating the SQL statement for a sequence value query:
@@ -119,5 +115,5 @@ public static class SessionExtensions
}
}
```
-snippet source | anchor
+snippet source | anchor
diff --git a/docs/schema/extensions.md b/docs/schema/extensions.md
index 6169af026a..75e9e8b8b5 100644
--- a/docs/schema/extensions.md
+++ b/docs/schema/extensions.md
@@ -7,25 +7,25 @@ Not to worry though, Marten comes with a base class that makes it a bit simpler
```cs
-public class FakeStorage : FeatureSchemaBase
+public class FakeStorage: FeatureSchemaBase
{
private readonly StoreOptions _options;
- public FakeStorage(StoreOptions options) : base("fake", options.Advanced.Migrator)
+ public FakeStorage(StoreOptions options): base("fake", options.Advanced.Migrator)
{
_options = options;
}
protected override IEnumerable schemaObjects()
{
- var table = new Table(new DbObjectName(_options.DatabaseSchemaName, "mt_fake_table"));
+ var table = new Table(new PostgresqlObjectName(_options.DatabaseSchemaName, "mt_fake_table"));
table.AddColumn("name", "varchar");
yield return table;
}
}
```
-snippet source | anchor
+snippet source | anchor
Now, to actually apply this feature to your Marten applications, use this syntax:
@@ -44,20 +44,23 @@ var store = DocumentStore.For(_ =>
_.Storage.Add(new FakeStorage(_));
});
```
-snippet source | anchor
+snippet source | anchor
Do note that when you use the `Add()` syntax, Marten will pass along the current `StoreOptions` to the constructor function if there is a constructor with that signature. Otherwise, it uses the no-arg constructor.
-While you *can* directly implement the `ISchemaObject` interface for something Marten doesn't already support. Marten provides an even easier extensibility mechanism to add custom database objects such as Postgres tables, functions and sequences using `StorageFeatures.ExtendedSchemaObjects` using [Weasel](https://github.com/JasperFx/weasel).
+While you
+*can* directly implement the `ISchemaObject` interface for something Marten doesn't already support. Marten provides an even easier extensibility mechanism to add custom database objects such as Postgres tables, functions and sequences using `StorageFeatures.ExtendedSchemaObjects` using [Weasel](https://github.com/JasperFx/weasel).
::: warning
-Marten will apply **Schema Feature Extensions** automatically when you call `ApplyAllConfiguredChangesToDatabaseAsync` for:
+Marten will apply **Schema Feature Extensions
+** automatically when you call `ApplyAllConfiguredChangesToDatabaseAsync` for:
* single schema configuration,
* [multi-tenancy per database](/configuration/multitenancy) with tenants known upfront.
-But it **won't apply them** for multi-tenancy per database with **unknown** tenants. If you cannot predict them, read the guidance on [dynamically applying changes to tenants databases](/configuration/multitenancy#dynamically-applying-changes-to-tenants-databases).
+But it **won't apply them** for multi-tenancy per database with **unknown
+** tenants. If you cannot predict them, read the guidance on [dynamically applying changes to tenants databases](/configuration/multitenancy#dynamically-applying-changes-to-tenants-databases).
:::
## Table
@@ -94,7 +97,7 @@ StoreOptions(opts =>
opts.RegisterDocumentType();
// Create a user defined function to act as a ternary operator similar to SQL Server
- var function = new Function(new DbObjectName("public", "iif"), @"
+ var function = new Function(new PostgresqlObjectName("public", "iif"), @"
create or replace function iif(
condition boolean, -- if condition
true_result anyelement, -- then
@@ -109,7 +112,7 @@ $f$ language sql immutable;
await theStore.Storage.ApplyAllConfiguredChangesToDatabaseAsync();
```
-snippet source | anchor
+snippet source | anchor
## Sequence
@@ -131,7 +134,7 @@ StoreOptions(opts =>
await theStore.Storage.ApplyAllConfiguredChangesToDatabaseAsync();
```
-snippet source | anchor
+snippet source | anchor
## Extension
diff --git a/src/CoreTests/DocumentCleanerTests.cs b/src/CoreTests/DocumentCleanerTests.cs
index e01e54ce9a..105ab40681 100644
--- a/src/CoreTests/DocumentCleanerTests.cs
+++ b/src/CoreTests/DocumentCleanerTests.cs
@@ -12,7 +12,7 @@
namespace CoreTests;
-public class DocumentCleanerTests : OneOffConfigurationsContext
+public class DocumentCleanerTests: OneOffConfigurationsContext
{
private IDocumentCleaner theCleaner => theStore.Advanced.Clean;
@@ -224,6 +224,5 @@ int GetSequenceCount(IDocumentStore store)
await theStore.Advanced.Clean.CompletelyRemoveAllAsync();
GetSequenceCount(theStore).ShouldBe(0);
-
}
}
diff --git a/src/CoreTests/adding_custom_schema_objects.cs b/src/CoreTests/adding_custom_schema_objects.cs
index f0d64d3e8e..be8fe67027 100644
--- a/src/CoreTests/adding_custom_schema_objects.cs
+++ b/src/CoreTests/adding_custom_schema_objects.cs
@@ -149,8 +149,10 @@ public async Task enable_an_extension_with_multitenancy_with_tenants_upfront_thr
});
#region sample_manual_single_tenancy_apply_changes
+
var tenant = await theStore.Tenancy.GetTenantAsync(tenantId);
await tenant.Database.ApplyAllConfiguredChangesToDatabaseAsync();
+
#endregion
await using var sessionNext = theStore.QuerySession(tenantId);
@@ -194,7 +196,7 @@ public async Task create_a_function()
opts.RegisterDocumentType();
// Create a user defined function to act as a ternary operator similar to SQL Server
- var function = new Function(new DbObjectName("public", "iif"), @"
+ var function = new Function(new PostgresqlObjectName("public", "iif"), @"
create or replace function iif(
condition boolean, -- if condition
true_result anyelement, -- then
diff --git a/src/DocumentDbTests/Bugs/Bug_2523_using_query_on_custom_storage_table.cs b/src/DocumentDbTests/Bugs/Bug_2523_using_query_on_custom_storage_table.cs
index abb7a45671..491d42c891 100644
--- a/src/DocumentDbTests/Bugs/Bug_2523_using_query_on_custom_storage_table.cs
+++ b/src/DocumentDbTests/Bugs/Bug_2523_using_query_on_custom_storage_table.cs
@@ -6,12 +6,13 @@
using Marten.Testing.Harness;
using Weasel.Core;
using Weasel.Core.Migrations;
+using Weasel.Postgresql;
using Weasel.Postgresql.Tables;
using Xunit;
namespace DocumentDbTests.Bugs;
-public class Bug_2523_using_query_on_custom_storage_table : BugIntegrationContext
+public class Bug_2523_using_query_on_custom_storage_table: BugIntegrationContext
{
[Fact]
public async Task WhenCustomTableIsUsedInABatchWithOtherDocumentResetAllShouldWork()
@@ -27,25 +28,26 @@ public async Task WhenCustomTableIsUsedInABatchWithOtherDocumentResetAllShouldWo
await using var session = store.LightweightSession();
session.QueueSqlCommand(CustomTableStorage.InsertSql, Guid.NewGuid().ToString());
- session.Insert(new User{FirstName = "John", LastName = "Doe"});
+ session.Insert(new User { FirstName = "John", LastName = "Doe" });
await session.SaveChangesAsync();
await store.Advanced.ResetAllData();
}
}
-public class CustomTableStorage : FeatureSchemaBase
+public class CustomTableStorage: FeatureSchemaBase
{
private const string TableName = "mt_custom_table";
public const string InsertSql = $"insert into bugs.{TableName}(id) values(?)";
private readonly StoreOptions _options;
- public CustomTableStorage(StoreOptions options) : base("custom_table", options.Advanced.Migrator) => _options = options;
+ public CustomTableStorage(StoreOptions options): base("custom_table", options.Advanced.Migrator) =>
+ _options = options;
protected override IEnumerable schemaObjects()
{
- var table = new Table(new DbObjectName("bugs", TableName));
+ var table = new Table(new PostgresqlObjectName("bugs", TableName));
table.AddColumn("id").AsPrimaryKey();
yield return table;
}
diff --git a/src/DocumentDbTests/Bugs/Bug_PR_1412_spaces_in_table_name_cause_schema_patch_to_fail.cs b/src/DocumentDbTests/Bugs/Bug_PR_1412_spaces_in_table_name_cause_schema_patch_to_fail.cs
index aaf750a1b6..ca5b74c162 100644
--- a/src/DocumentDbTests/Bugs/Bug_PR_1412_spaces_in_table_name_cause_schema_patch_to_fail.cs
+++ b/src/DocumentDbTests/Bugs/Bug_PR_1412_spaces_in_table_name_cause_schema_patch_to_fail.cs
@@ -98,9 +98,9 @@ internal class spaceAfterTableNameSchema: testSchema
{
protected override IEnumerable SchemaObjects()
{
- var table = new Table(new DbObjectName(SchemaConstants.DefaultSchema,"test_space_after"));
+ var table = new Table(new PostgresqlObjectName(SchemaConstants.DefaultSchema, "test_space_after"));
table.AddColumn("space_after ", "int");
- return new List {table};
+ return new List { table };
}
}
@@ -108,9 +108,9 @@ internal class spaceBeforeTableNameSchema: testSchema
{
protected override IEnumerable SchemaObjects()
{
- var table = new Table(new DbObjectName(SchemaConstants.DefaultSchema,"test_space_before"));
+ var table = new Table(new PostgresqlObjectName(SchemaConstants.DefaultSchema, "test_space_before"));
table.AddColumn(" space_before", "int");
- return new List {table};
+ return new List { table };
}
}
@@ -118,9 +118,9 @@ internal class spaceInNameSchema: testSchema
{
protected override IEnumerable SchemaObjects()
{
- var table = new Table(new DbObjectName(SchemaConstants.DefaultSchema,"test_space_in"));
+ var table = new Table(new PostgresqlObjectName(SchemaConstants.DefaultSchema, "test_space_in"));
table.AddColumn("space inname", "int");
- return new List {table};
+ return new List { table };
}
}
-}
\ No newline at end of file
+}
diff --git a/src/DocumentDbTests/Bugs/bug_1338_Validate_Null_ForeignKeyDefinition_ReferenceDocumenType.cs b/src/DocumentDbTests/Bugs/bug_1338_Validate_Null_ForeignKeyDefinition_ReferenceDocumenType.cs
index 9b41ea3935..1ad51e3bb3 100644
--- a/src/DocumentDbTests/Bugs/bug_1338_Validate_Null_ForeignKeyDefinition_ReferenceDocumenType.cs
+++ b/src/DocumentDbTests/Bugs/bug_1338_Validate_Null_ForeignKeyDefinition_ReferenceDocumenType.cs
@@ -17,12 +17,13 @@ public class Bug_1338_Validate_Null_ForeignKeyDefinition_ReferenceDocumenType: B
[Fact]
public void StorageFeatures_AllActiveFeatures_Should_Not_Throw_With_ExternalForeignKeyDefinitions()
{
- theStore.StorageFeatures.AllActiveFeatures(theStore.Tenancy.Default.Database).All(x => x != null).ShouldBeTrue();
+ theStore.StorageFeatures.AllActiveFeatures(theStore.Tenancy.Default.Database).All(x => x != null)
+ .ShouldBeTrue();
}
public async Task InitializeAsync()
{
- var table = new Table(new DbObjectName(SchemaName, "external_table"));
+ var table = new Table(new PostgresqlObjectName(SchemaName, "external_table"));
table.AddColumn("id", "integer").AsPrimaryKey();
await using var dbConn = new NpgsqlConnection(ConnectionSource.ConnectionString);
@@ -40,7 +41,6 @@ public async Task InitializeAsync()
}, false);
await theStore.Advanced.Clean.DeleteDocumentsByTypeAsync(typeof(ClassWithExternalForeignKey));
-
}
public Task DisposeAsync()
@@ -60,10 +60,9 @@ public async Task UnitOfWork_GetTypeDependencies_Should_Not_Throw_With_ExternalF
// and finally, the function that we want to regression test"
// UnitOfWork.GetTypeDependencies(ClassWithExternalForeignKey)
await using var session = theStore.LightweightSession();
- session.Insert(new ClassWithExternalForeignKey {Id = 1, ForeignId = 1});
+ session.Insert(new ClassWithExternalForeignKey { Id = 1, ForeignId = 1 });
await session.SaveChangesAsync();
}
-
}
public class ClassWithExternalForeignKey
diff --git a/src/DocumentDbTests/Configuration/ability_to_add_custom_storage_features.cs b/src/DocumentDbTests/Configuration/ability_to_add_custom_storage_features.cs
index aab91606b1..7653ec2bd2 100644
--- a/src/DocumentDbTests/Configuration/ability_to_add_custom_storage_features.cs
+++ b/src/DocumentDbTests/Configuration/ability_to_add_custom_storage_features.cs
@@ -6,18 +6,17 @@
using Shouldly;
using Weasel.Core;
using Weasel.Core.Migrations;
+using Weasel.Postgresql;
using Weasel.Postgresql.Tables;
using Xunit;
namespace DocumentDbTests.Configuration;
-public class ability_to_add_custom_storage_features : OneOffConfigurationsContext
+public class ability_to_add_custom_storage_features: OneOffConfigurationsContext
{
[Fact]
public async Task can_register_a_custom_feature()
{
-
-
StoreOptions(_ =>
{
_.Storage.Add();
@@ -31,6 +30,7 @@ public async Task can_register_a_custom_feature()
public void using_custom_feature_schema()
{
#region sample_adding-schema-feature
+
var store = DocumentStore.For(_ =>
{
// Creates a new instance of FakeStorage and
@@ -41,27 +41,29 @@ public void using_custom_feature_schema()
_.Storage.Add(new FakeStorage(_));
});
+
#endregion
}
}
#region sample_creating-a-fake-schema-feature
-public class FakeStorage : FeatureSchemaBase
+
+public class FakeStorage: FeatureSchemaBase
{
private readonly StoreOptions _options;
- public FakeStorage(StoreOptions options) : base("fake", options.Advanced.Migrator)
+ public FakeStorage(StoreOptions options): base("fake", options.Advanced.Migrator)
{
_options = options;
}
protected override IEnumerable schemaObjects()
{
- var table = new Table(new DbObjectName(_options.DatabaseSchemaName, "mt_fake_table"));
+ var table = new Table(new PostgresqlObjectName(_options.DatabaseSchemaName, "mt_fake_table"));
table.AddColumn("name", "varchar");
yield return table;
}
}
-#endregion
\ No newline at end of file
+#endregion
diff --git a/src/EventSourcingTests/Projections/Flattened/FlatTableProjectionTests.cs b/src/EventSourcingTests/Projections/Flattened/FlatTableProjectionTests.cs
index 28f7203509..6016f408e0 100644
--- a/src/EventSourcingTests/Projections/Flattened/FlatTableProjectionTests.cs
+++ b/src/EventSourcingTests/Projections/Flattened/FlatTableProjectionTests.cs
@@ -9,6 +9,7 @@
using Marten.Exceptions;
using Shouldly;
using Weasel.Core;
+using Weasel.Postgresql;
using Weasel.Postgresql.Tables;
using Xunit;
@@ -78,7 +79,7 @@ public void use_explicit_schema_name_1()
[Fact]
public void use_explicit_schema_name_2()
{
- var projection = new FlatTableProjection(new DbObjectName("special", "foo"));
+ var projection = new FlatTableProjection(new PostgresqlObjectName("special", "foo"));
projection.Table.AddColumn("id").AsPrimaryKey();
projection.Delete();
@@ -112,7 +113,9 @@ public void use_schema_from_event_graph()
projection.Delete();
var events = new EventGraph(new StoreOptions { DatabaseSchemaName = "fromdocstore" })
- {DatabaseSchemaName = "FromEventGraph"};
+ {
+ DatabaseSchemaName = "FromEventGraph"
+ };
var table = projection.As()
.CreateSchemaObjects(events).OfType().Single();
diff --git a/src/EventSourcingTests/Projections/Flattened/flat_table_projection_with_event_member_identifier_end_to_end.cs b/src/EventSourcingTests/Projections/Flattened/flat_table_projection_with_event_member_identifier_end_to_end.cs
index 1c99718c70..af1cba0a38 100644
--- a/src/EventSourcingTests/Projections/Flattened/flat_table_projection_with_event_member_identifier_end_to_end.cs
+++ b/src/EventSourcingTests/Projections/Flattened/flat_table_projection_with_event_member_identifier_end_to_end.cs
@@ -10,13 +10,15 @@
using Npgsql;
using Shouldly;
using Weasel.Core;
+using Weasel.Postgresql;
using Weasel.Postgresql.Tables;
using Xunit;
using Xunit.Abstractions;
+using CommandExtensions = Weasel.Core.CommandExtensions;
namespace EventSourcingTests.Projections.Flattened;
-public class flat_table_projection_with_event_member_identifier_end_to_end : OneOffConfigurationsContext
+public class flat_table_projection_with_event_member_identifier_end_to_end: OneOffConfigurationsContext
{
private readonly ITestOutputHelper _output;
@@ -38,7 +40,7 @@ public async Task table_should_be_built()
await using var conn = theStore.Storage.Database.CreateConnection();
await conn.OpenAsync();
- var table = await new Table(new DbObjectName(SchemaName, "member_values")).FetchExistingAsync(conn);
+ var table = await new Table(new PostgresqlObjectName(SchemaName, "member_values")).FetchExistingAsync(conn);
table.PrimaryKeyColumns.Single().ShouldBe("name");
table.Columns.Select(x => x.Name).OrderBy(x => x)
@@ -77,7 +79,8 @@ private async Task findData(string name)
await using var conn = theStore.Storage.Database.CreateConnection();
await conn.OpenAsync();
- var all = await conn.CreateCommand($"select * from {SchemaName}.member_values where name = :id")
+ var all = await CommandExtensions
+ .CreateCommand(conn, $"select * from {SchemaName}.member_values where name = :id")
.With("id", name)
.FetchListAsync(readData);
@@ -91,7 +94,11 @@ public async Task set_values_on_new_row()
var streamId = Guid.NewGuid().ToString();
var valuesSet = new ValuesSet
{
- A = 3, B = 4, C = 5, D = 6, Name = "red"
+ A = 3,
+ B = 4,
+ C = 5,
+ D = 6,
+ Name = "red"
};
theSession.Events.Append(streamId, valuesSet);
@@ -114,13 +121,28 @@ public async Task set_values_on_existing_row()
var streamId = Guid.NewGuid().ToString();
var guid = Guid.NewGuid();
var now = DateTimeOffset.UtcNow;
- theSession.Events.Append(streamId, new ValuesSet { A = 1, B = 2, C = 3, D = 4, Name = "blue", Guid = guid, Time = now});
+ theSession.Events.Append(streamId, new ValuesSet
+ {
+ A = 1,
+ B = 2,
+ C = 3,
+ D = 4,
+ Name = "blue",
+ Guid = guid,
+ Time = now
+ });
await theSession.SaveChangesAsync();
var valuesSet = new ValuesSet
{
- A = 3, B = 4, C = 5, D = 6, Name = "blue", Guid = guid, Time = now
+ A = 3,
+ B = 4,
+ C = 5,
+ D = 6,
+ Name = "blue",
+ Guid = guid,
+ Time = now
};
theSession.Events.Append(streamId, valuesSet);
@@ -145,13 +167,24 @@ public async Task set_values_on_existing_row()
public async Task increment_values_on_existing_row()
{
var streamId = Guid.NewGuid().ToString();
- theSession.Events.Append(streamId, new ValuesSet { A = 1, B = 2, C = 3, D = 4, Name = "green"});
+ theSession.Events.Append(streamId, new ValuesSet
+ {
+ A = 1,
+ B = 2,
+ C = 3,
+ D = 4,
+ Name = "green"
+ });
await theSession.SaveChangesAsync();
var valuesAdded = new ValuesAdded
{
- A = 3, B = 4, C = 5, D = 6, Name = "green"
+ A = 3,
+ B = 4,
+ C = 5,
+ D = 6,
+ Name = "green"
};
theSession.Events.Append(streamId, valuesAdded);
@@ -173,13 +206,24 @@ public async Task increment_values_on_existing_row()
public async Task decrement_values_on_existing_row()
{
var streamId = Guid.NewGuid().ToString();
- theSession.Events.Append(streamId, new ValuesSet { A = 10, B = 10, C = 10, D = 10, Name = "orange"});
+ theSession.Events.Append(streamId, new ValuesSet
+ {
+ A = 10,
+ B = 10,
+ C = 10,
+ D = 10,
+ Name = "orange"
+ });
await theSession.SaveChangesAsync();
var valuesAdded = new ValuesSubtracted
{
- A = 3, B = 4, C = 5, D = 6, Name = "orange"
+ A = 3,
+ B = 4,
+ C = 5,
+ D = 6,
+ Name = "orange"
};
theSession.Events.Append("orange", valuesAdded);
@@ -192,7 +236,6 @@ public async Task decrement_values_on_existing_row()
data.B.ShouldBe(6);
data.C.ShouldBe(5);
data.D.ShouldBe(4);
-
}
[Fact]
@@ -202,22 +245,29 @@ public async Task delete_a_row()
var time = DateTimeOffset.UtcNow;
var streamId = Guid.NewGuid().ToString();
- theSession.Events.Append(streamId, new ValuesSet { A = 10, B = 10, C = 10, D = 10, Name = "purple", Guid = guid, Time = time});
+ theSession.Events.Append(streamId, new ValuesSet
+ {
+ A = 10,
+ B = 10,
+ C = 10,
+ D = 10,
+ Name = "purple",
+ Guid = guid,
+ Time = time
+ });
await theSession.SaveChangesAsync();
- theSession.Events.Append(streamId, new ValuesDeleted{Name = "purple"});
+ theSession.Events.Append(streamId, new ValuesDeleted { Name = "purple" });
await theSession.SaveChangesAsync();
await using var conn = new NpgsqlConnection(ConnectionSource.ConnectionString);
await conn.OpenAsync();
- var count = await conn
- .CreateCommand($"select count(*) from {SchemaName}.member_values where name = :id")
+ var count = await CommandExtensions
+ .CreateCommand(conn, $"select count(*) from {SchemaName}.member_values where name = :id")
.With("id", "purple")
.ExecuteScalarAsync();
count.As().ShouldBe(0);
-
-
}
}
diff --git a/src/EventSourcingTests/Projections/Flattened/flat_table_projection_with_stream_id_identifier_end_to_end.cs b/src/EventSourcingTests/Projections/Flattened/flat_table_projection_with_stream_id_identifier_end_to_end.cs
index aeeef5a1f2..cbc474582f 100644
--- a/src/EventSourcingTests/Projections/Flattened/flat_table_projection_with_stream_id_identifier_end_to_end.cs
+++ b/src/EventSourcingTests/Projections/Flattened/flat_table_projection_with_stream_id_identifier_end_to_end.cs
@@ -10,6 +10,7 @@
using Npgsql;
using Shouldly;
using Weasel.Core;
+using Weasel.Postgresql;
using Weasel.Postgresql.Tables;
using Xunit;
using Xunit.Abstractions;
@@ -17,7 +18,7 @@
namespace EventSourcingTests.Projections.Flattened;
-public class flat_table_projection_with_stream_id_identifier_end_to_end : OneOffConfigurationsContext
+public class flat_table_projection_with_stream_id_identifier_end_to_end: OneOffConfigurationsContext
{
private readonly ITestOutputHelper _output;
@@ -38,7 +39,7 @@ public async Task table_should_be_built()
await using var conn = theStore.Storage.Database.CreateConnection();
await conn.OpenAsync();
- var table = await new Table(new DbObjectName(SchemaName, "values")).FetchExistingAsync(conn);
+ var table = await new Table(new PostgresqlObjectName(SchemaName, "values")).FetchExistingAsync(conn);
table.PrimaryKeyColumns.Single().ShouldBe("id");
table.Columns.Select(x => x.Name).OrderBy(x => x)
@@ -73,7 +74,8 @@ private async Task findData(Guid streamId)
await using var conn = theStore.Storage.Database.CreateConnection();
await conn.OpenAsync();
- var all = await conn.CreateCommand($"select * from {SchemaName}.values where id = :id")
+ var all = await Weasel.Core.CommandExtensions
+ .CreateCommand(conn, $"select * from {SchemaName}.values where id = :id")
.With("id", streamId)
.FetchListAsync(readData);
@@ -97,10 +99,7 @@ public async Task functions_are_built()
public async Task set_values_on_new_row()
{
var streamId = Guid.NewGuid();
- var valuesSet = new ValuesSet
- {
- A = 3, B = 4, C = 5, D = 6
- };
+ var valuesSet = new ValuesSet { A = 3, B = 4, C = 5, D = 6 };
theSession.Events.Append(streamId, valuesSet);
await theSession.SaveChangesAsync();
@@ -124,10 +123,7 @@ public async Task set_values_on_existing_row()
await theSession.SaveChangesAsync();
- var valuesSet = new ValuesSet
- {
- A = 3, B = 4, C = 5, D = 6
- };
+ var valuesSet = new ValuesSet { A = 3, B = 4, C = 5, D = 6 };
theSession.Events.Append(streamId, valuesSet);
@@ -152,10 +148,7 @@ public async Task increment_values_on_existing_row()
await theSession.SaveChangesAsync();
- var valuesAdded = new ValuesAdded
- {
- A = 3, B = 4, C = 5, D = 6
- };
+ var valuesAdded = new ValuesAdded { A = 3, B = 4, C = 5, D = 6 };
theSession.Events.Append(streamId, valuesAdded);
@@ -180,10 +173,7 @@ public async Task decrement_values_on_existing_row()
await theSession.SaveChangesAsync();
- var valuesAdded = new ValuesSubtracted
- {
- A = 3, B = 4, C = 5, D = 6
- };
+ var valuesAdded = new ValuesSubtracted { A = 3, B = 4, C = 5, D = 6 };
theSession.Events.Append(streamId, valuesAdded);
@@ -195,7 +185,6 @@ public async Task decrement_values_on_existing_row()
data.B.ShouldBe(6);
data.C.ShouldBe(5);
data.D.ShouldBe(4);
-
}
[Fact]
@@ -211,13 +200,11 @@ public async Task delete_a_row()
await using var conn = new NpgsqlConnection(ConnectionSource.ConnectionString);
await conn.OpenAsync();
- var count = await conn
- .CreateCommand($"select count(*) from {SchemaName}.values where id = :id")
+ var count = await Weasel.Core.CommandExtensions
+ .CreateCommand(conn, $"select count(*) from {SchemaName}.values where id = :id")
.With("id", streamId)
.ExecuteScalarAsync();
count.As().ShouldBe(0);
-
-
}
}
diff --git a/src/EventSourcingTests/Projections/Flattened/flat_table_projection_with_stream_key_identifier_end_to_end.cs b/src/EventSourcingTests/Projections/Flattened/flat_table_projection_with_stream_key_identifier_end_to_end.cs
index ec09d45b0b..1ea50c7813 100644
--- a/src/EventSourcingTests/Projections/Flattened/flat_table_projection_with_stream_key_identifier_end_to_end.cs
+++ b/src/EventSourcingTests/Projections/Flattened/flat_table_projection_with_stream_key_identifier_end_to_end.cs
@@ -10,13 +10,15 @@
using Npgsql;
using Shouldly;
using Weasel.Core;
+using Weasel.Postgresql;
using Weasel.Postgresql.Tables;
using Xunit;
using Xunit.Abstractions;
+using CommandExtensions = Weasel.Core.CommandExtensions;
namespace EventSourcingTests.Projections.Flattened;
-public class flat_table_projection_with_stream_key_identifier_end_to_end : OneOffConfigurationsContext
+public class flat_table_projection_with_stream_key_identifier_end_to_end: OneOffConfigurationsContext
{
private readonly ITestOutputHelper _output;
@@ -38,7 +40,7 @@ public async Task table_should_be_built()
await using var conn = theStore.Storage.Database.CreateConnection();
await conn.OpenAsync();
- var table = await new Table(new DbObjectName(SchemaName, "string_values")).FetchExistingAsync(conn);
+ var table = await new Table(new PostgresqlObjectName(SchemaName, "string_values")).FetchExistingAsync(conn);
table.PrimaryKeyColumns.Single().ShouldBe("id");
table.Columns.Select(x => x.Name).OrderBy(x => x)
@@ -73,7 +75,8 @@ private async Task findData(string streamId)
await using var conn = theStore.Storage.Database.CreateConnection();
await conn.OpenAsync();
- var all = await conn.CreateCommand($"select * from {SchemaName}.string_values where id = :id")
+ var all = await CommandExtensions
+ .CreateCommand(conn, $"select * from {SchemaName}.string_values where id = :id")
.With("id", streamId)
.FetchListAsync(readData);
@@ -85,10 +88,7 @@ private async Task findData(string streamId)
public async Task set_values_on_new_row()
{
var streamId = Guid.NewGuid().ToString();
- var valuesSet = new ValuesSet
- {
- A = 3, B = 4, C = 5, D = 6
- };
+ var valuesSet = new ValuesSet { A = 3, B = 4, C = 5, D = 6 };
theSession.Events.Append(streamId, valuesSet);
await theSession.SaveChangesAsync();
@@ -112,10 +112,7 @@ public async Task set_values_on_existing_row()
await theSession.SaveChangesAsync();
- var valuesSet = new ValuesSet
- {
- A = 3, B = 4, C = 5, D = 6
- };
+ var valuesSet = new ValuesSet { A = 3, B = 4, C = 5, D = 6 };
theSession.Events.Append(streamId, valuesSet);
@@ -140,10 +137,7 @@ public async Task increment_values_on_existing_row()
await theSession.SaveChangesAsync();
- var valuesAdded = new ValuesAdded
- {
- A = 3, B = 4, C = 5, D = 6
- };
+ var valuesAdded = new ValuesAdded { A = 3, B = 4, C = 5, D = 6 };
theSession.Events.Append(streamId, valuesAdded);
@@ -168,10 +162,7 @@ public async Task decrement_values_on_existing_row()
await theSession.SaveChangesAsync();
- var valuesAdded = new ValuesSubtracted
- {
- A = 3, B = 4, C = 5, D = 6
- };
+ var valuesAdded = new ValuesSubtracted { A = 3, B = 4, C = 5, D = 6 };
theSession.Events.Append(streamId, valuesAdded);
@@ -183,7 +174,6 @@ public async Task decrement_values_on_existing_row()
data.B.ShouldBe(6);
data.C.ShouldBe(5);
data.D.ShouldBe(4);
-
}
[Fact]
@@ -199,13 +189,11 @@ public async Task delete_a_row()
await using var conn = new NpgsqlConnection(ConnectionSource.ConnectionString);
await conn.OpenAsync();
- var count = await conn
- .CreateCommand($"select count(*) from {SchemaName}.string_values where id = :id")
+ var count = await CommandExtensions
+ .CreateCommand(conn, $"select count(*) from {SchemaName}.string_values where id = :id")
.With("id", streamId)
.ExecuteScalarAsync();
count.As().ShouldBe(0);
-
-
}
}
diff --git a/src/EventSourcingTests/Projections/include_extra_schema_objects_from_projections.cs b/src/EventSourcingTests/Projections/include_extra_schema_objects_from_projections.cs
index 36a5384191..9fa8cb1596 100644
--- a/src/EventSourcingTests/Projections/include_extra_schema_objects_from_projections.cs
+++ b/src/EventSourcingTests/Projections/include_extra_schema_objects_from_projections.cs
@@ -25,7 +25,7 @@ public include_extra_schema_objects_from_projections()
[Fact]
public void has_the_additional_table_in_events_schema_feature()
{
- var tableName = new DbObjectName("extra", "names");
+ var tableName = new PostgresqlObjectName("extra", "names");
var feature = theStore.Options.Storage.FindFeature(typeof(IEvent));
feature.Objects.OfType().Any(x => Equals(x.Identifier, tableName)).ShouldBeTrue();
@@ -34,7 +34,7 @@ public void has_the_additional_table_in_events_schema_feature()
[Fact]
public async Task build_feature_adds_the_table()
{
- var tableName = new DbObjectName("extra", "names");
+ var tableName = new PostgresqlObjectName("extra", "names");
await using (var conn = theStore.Storage.Database.CreateConnection())
{
@@ -63,7 +63,7 @@ public class TableCreatingProjection: EventProjection
{
public TableCreatingProjection()
{
- var table = new Table(new DbObjectName("extra", "names"));
+ var table = new Table(new PostgresqlObjectName("extra", "names"));
table.AddColumn("name").AsPrimaryKey();
SchemaObjects.Add(table);
diff --git a/src/Marten.PLv8.Testing/Patching/Bug_593_patch_doc_function_should_be_built_in_designated_schema.cs b/src/Marten.PLv8.Testing/Patching/Bug_593_patch_doc_function_should_be_built_in_designated_schema.cs
index f1e840bd49..13db271d72 100644
--- a/src/Marten.PLv8.Testing/Patching/Bug_593_patch_doc_function_should_be_built_in_designated_schema.cs
+++ b/src/Marten.PLv8.Testing/Patching/Bug_593_patch_doc_function_should_be_built_in_designated_schema.cs
@@ -22,8 +22,7 @@ public async Task should_stick_the_patch_doc_function_in_the_right_schema()
await theStore.Storage.ApplyAllConfiguredChangesToDatabaseAsync();
- var expected = new DbObjectName("other", "mt_transform_patch_doc");
+ var expected = new PostgresqlObjectName("other", "mt_transform_patch_doc");
(await theStore.Tenancy.Default.Database.Functions()).Contains(expected).ShouldBeTrue();
}
-
-}
\ No newline at end of file
+}
diff --git a/src/Marten.PLv8/Transforms/TransformFunction.cs b/src/Marten.PLv8/Transforms/TransformFunction.cs
index 18e96842d5..378c4b51dd 100644
--- a/src/Marten.PLv8/Transforms/TransformFunction.cs
+++ b/src/Marten.PLv8/Transforms/TransformFunction.cs
@@ -5,6 +5,7 @@
using System.Reflection;
using JasperFx.Core;
using Weasel.Core;
+using Weasel.Postgresql;
using Weasel.Postgresql.Functions;
namespace Marten.PLv8.Transforms;
@@ -16,7 +17,7 @@ public class TransformFunction: Function
public readonly IList OtherArgs = new List();
public TransformFunction(StoreOptions options, string name, string body)
- : base(new DbObjectName(options.DatabaseSchemaName, "mt_transform_" + name.Replace(".", "_")))
+ : base(new PostgresqlObjectName(options.DatabaseSchemaName, "mt_transform_" + name.Replace(".", "_")))
{
Name = name;
Body = body;
@@ -73,7 +74,8 @@ public static TransformFunction ForFile(StoreOptions options, string file, strin
return new TransformFunction(options, name, body);
}
- public static TransformFunction ForResource(StoreOptions options, Assembly assembly, string resource, string name = null)
+ public static TransformFunction ForResource(StoreOptions options, Assembly assembly, string resource,
+ string name = null)
{
using var stream = assembly.GetManifestResourceStream(resource);
if (stream == null)
diff --git a/src/Marten.Testing/Examples/ScenarioUsingSequenceForUniqueId.cs b/src/Marten.Testing/Examples/ScenarioUsingSequenceForUniqueId.cs
index 06505d3194..f74198eba1 100644
--- a/src/Marten.Testing/Examples/ScenarioUsingSequenceForUniqueId.cs
+++ b/src/Marten.Testing/Examples/ScenarioUsingSequenceForUniqueId.cs
@@ -10,18 +10,17 @@
namespace Marten.Testing.Examples;
-public class ScenarioUsingSequenceForUniqueId : OneOffConfigurationsContext
+public class ScenarioUsingSequenceForUniqueId: OneOffConfigurationsContext
{
-
-
#region sample_scenario-usingsequenceforuniqueid-setup
+
// We introduce a new feature schema, making use of Marten's schema management facilities.
public class MatterId: FeatureSchemaBase
{
private readonly int _startFrom;
private readonly string _schema;
- public MatterId(StoreOptions options, int startFrom) : base(nameof(MatterId), options.Advanced.Migrator)
+ public MatterId(StoreOptions options, int startFrom): base(nameof(MatterId), options.Advanced.Migrator)
{
_startFrom = startFrom;
_schema = options.DatabaseSchemaName;
@@ -30,9 +29,11 @@ public MatterId(StoreOptions options, int startFrom) : base(nameof(MatterId), op
protected override IEnumerable schemaObjects()
{
// We return a sequence that starts from the value provided in the ctor
- yield return new Sequence(new DbObjectName(_schema, $"mt_{nameof(MatterId).ToLowerInvariant()}"), _startFrom);
+ yield return new Sequence(new PostgresqlObjectName(_schema, $"mt_{nameof(MatterId).ToLowerInvariant()}"),
+ _startFrom);
}
}
+
#endregion
[Fact]
@@ -41,32 +42,29 @@ public async Task ScenarioUsingSequenceForUniqueIdScenario()
StoreOptions(storeOptions =>
{
#region sample_scenario-usingsequenceforuniqueid-storesetup-1
+
storeOptions.Storage.Add(new MatterId(storeOptions, 10000));
+
#endregion
});
#region sample_scenario-usingsequenceforuniqueid-storesetup-2
+
await theStore.Storage.ApplyAllConfiguredChangesToDatabaseAsync();
+
#endregion
#region sample_scenario-usingsequenceforuniqueid-querymatter
+
var matter = theStore.StorageFeatures.FindFeature(typeof(MatterId)).Objects.OfType().Single();
await using var session = theStore.LightweightSession();
// Generate a new, unique identifier
var nextMatter = session.NextInSequence(matter);
- var contract = new Contract
- {
- Id = Guid.NewGuid(),
- Matter = nextMatter
- };
+ var contract = new Contract { Id = Guid.NewGuid(), Matter = nextMatter };
- var inquiry = new Inquiry
- {
- Id = Guid.NewGuid(),
- Matter = nextMatter
- };
+ var inquiry = new Inquiry { Id = Guid.NewGuid(), Matter = nextMatter };
session.Store(contract);
session.Store(inquiry);
@@ -77,22 +75,28 @@ public async Task ScenarioUsingSequenceForUniqueIdScenario()
}
#region sample_scenario-usingsequenceforuniqueid-setup-types
+
public class Contract
{
public Guid Id { get; set; }
+
public int Matter { get; set; }
// Other fields...
}
+
public class Inquiry
{
public Guid Id { get; set; }
+
public int Matter { get; set; }
// Other fields...
}
- #endregion
+ #endregion
}
+
#region sample_scenario-usingsequenceforuniqueid-setup-extensions
+
public static class SessionExtensions
{
// A shorthand for generating the required SQL statement for a sequence value query
@@ -101,4 +105,5 @@ public static int NextInSequence(this IQuerySession session, Sequence sequence)
return session.Query("select nextval(?)", sequence.Identifier.QualifiedName).First();
}
}
+
#endregion
diff --git a/src/Marten/Events/Archiving/ArchiveStreamFunction.cs b/src/Marten/Events/Archiving/ArchiveStreamFunction.cs
index 28697430c2..2638b1f8bb 100644
--- a/src/Marten/Events/Archiving/ArchiveStreamFunction.cs
+++ b/src/Marten/Events/Archiving/ArchiveStreamFunction.cs
@@ -1,5 +1,6 @@
using System.IO;
using Weasel.Core;
+using Weasel.Postgresql;
using Weasel.Postgresql.Functions;
namespace Marten.Events.Archiving;
@@ -10,7 +11,7 @@ internal class ArchiveStreamFunction: Function
private readonly EventGraph _events;
- public ArchiveStreamFunction(EventGraph events): base(new DbObjectName(events.DatabaseSchemaName, Name))
+ public ArchiveStreamFunction(EventGraph events): base(new PostgresqlObjectName(events.DatabaseSchemaName, Name))
{
_events = events;
}
diff --git a/src/Marten/Events/EventGraph.FeatureSchema.cs b/src/Marten/Events/EventGraph.FeatureSchema.cs
index c3fbfe9a39..57fa96166a 100644
--- a/src/Marten/Events/EventGraph.FeatureSchema.cs
+++ b/src/Marten/Events/EventGraph.FeatureSchema.cs
@@ -16,8 +16,8 @@ namespace Marten.Events;
public partial class EventGraph: IFeatureSchema
{
- internal DbObjectName ProgressionTable => new(DatabaseSchemaName, "mt_event_progression");
- internal DbObjectName StreamsTable => new(DatabaseSchemaName, "mt_streams");
+ internal DbObjectName ProgressionTable => new PostgresqlObjectName(DatabaseSchemaName, "mt_event_progression");
+ internal DbObjectName StreamsTable => new PostgresqlObjectName(DatabaseSchemaName, "mt_streams");
IEnumerable IFeatureSchema.DependentTypes()
@@ -44,7 +44,7 @@ private IEnumerable createAllSchemaObjects()
#region sample_using-sequence
- var sequence = new Sequence(new DbObjectName(DatabaseSchemaName, "mt_events_sequence"))
+ var sequence = new Sequence(new PostgresqlObjectName(DatabaseSchemaName, "mt_events_sequence"))
{
Owner = eventsTable.Identifier, OwnerColumn = "seq_id"
};
@@ -56,7 +56,7 @@ private IEnumerable createAllSchemaObjects()
yield return new EventProgressionTable(DatabaseSchemaName);
yield return new SystemFunction(DatabaseSchemaName, "mt_mark_event_progression", "varchar, bigint");
- yield return Function.ForRemoval(new DbObjectName(DatabaseSchemaName, "mt_append_event"));
+ yield return Function.ForRemoval(new PostgresqlObjectName(DatabaseSchemaName, "mt_append_event"));
yield return new ArchiveStreamFunction(this);
foreach (var schemaSource in Options.Projections.All.OfType())
diff --git a/src/Marten/Events/EventGraph.cs b/src/Marten/Events/EventGraph.cs
index 70ca0f7903..21d81e866e 100644
--- a/src/Marten/Events/EventGraph.cs
+++ b/src/Marten/Events/EventGraph.cs
@@ -19,6 +19,7 @@
using Microsoft.Extensions.Logging.Abstractions;
using NpgsqlTypes;
using Weasel.Core;
+using Weasel.Postgresql;
using static Marten.Events.EventMappingExtensions;
namespace Marten.Events;
@@ -67,7 +68,7 @@ internal EventGraph(StoreOptions options)
internal StoreOptions Options { get; }
- internal DbObjectName Table => new(DatabaseSchemaName, "mt_events");
+ internal DbObjectName Table => new PostgresqlObjectName(DatabaseSchemaName, "mt_events");
internal EventMetadataCollection Metadata { get; } = new();
@@ -287,7 +288,7 @@ internal IReadOnlySet AliasesForEvents(IReadOnlyCollection types)
foreach (var mapping in _byEventName)
{
- if(mapping is null)
+ if (mapping is null)
continue;
if (types.Contains(mapping.DocumentType))
{
@@ -412,6 +413,7 @@ public async ValueTask DisposeAsync()
{
// Ignore this
}
+
Dispose();
}
}
diff --git a/src/Marten/Events/EventMapping.cs b/src/Marten/Events/EventMapping.cs
index ef22490edc..4035b534a2 100644
--- a/src/Marten/Events/EventMapping.cs
+++ b/src/Marten/Events/EventMapping.cs
@@ -89,7 +89,7 @@ protected EventMapping(EventGraph parent, Type eventType)
Type IDocumentMapping.IdType => typeof(Guid);
- public DbObjectName TableName => new(_parent.DatabaseSchemaName, "mt_events");
+ public DbObjectName TableName => new PostgresqlObjectName(_parent.DatabaseSchemaName, "mt_events");
Type IEventType.EventType => DocumentType;
diff --git a/src/Marten/Events/EventQueryMapping.cs b/src/Marten/Events/EventQueryMapping.cs
index e7db677368..ab869ef677 100644
--- a/src/Marten/Events/EventQueryMapping.cs
+++ b/src/Marten/Events/EventQueryMapping.cs
@@ -5,6 +5,7 @@
using Marten.Linq.Parsing;
using Marten.Schema;
using Weasel.Core;
+using Weasel.Postgresql;
namespace Marten.Events;
@@ -16,7 +17,7 @@ public EventQueryMapping(StoreOptions storeOptions): base(typeof(IEvent), storeO
TenancyStyle = storeOptions.Events.TenancyStyle;
- TableName = new DbObjectName(DatabaseSchemaName, "mt_events");
+ TableName = new PostgresqlObjectName(DatabaseSchemaName, "mt_events");
duplicateField(x => x.Sequence, "seq_id");
if (storeOptions.Events.StreamIdentity == StreamIdentity.AsGuid)
diff --git a/src/Marten/Events/Operations/EventProgressWrite.cs b/src/Marten/Events/Operations/EventProgressWrite.cs
index 75ce22ad0b..630eb1dc73 100644
--- a/src/Marten/Events/Operations/EventProgressWrite.cs
+++ b/src/Marten/Events/Operations/EventProgressWrite.cs
@@ -19,7 +19,7 @@ internal class EventProgressWrite: IStorageOperation
public EventProgressWrite(EventGraph events, string key, long number)
{
- _sproc = new DbObjectName(events.DatabaseSchemaName, "mt_mark_event_progression");
+ _sproc = new PostgresqlObjectName(events.DatabaseSchemaName, "mt_mark_event_progression");
_key = key;
_number = number;
}
diff --git a/src/Marten/Events/Projections/Flattened/FlatTableProjection.cs b/src/Marten/Events/Projections/Flattened/FlatTableProjection.cs
index 76ca78650a..c68a6e1a26 100644
--- a/src/Marten/Events/Projections/Flattened/FlatTableProjection.cs
+++ b/src/Marten/Events/Projections/Flattened/FlatTableProjection.cs
@@ -13,6 +13,7 @@
using Weasel.Core;
using Weasel.Postgresql.Tables;
using JasperFx.Core.Reflection;
+using Weasel.Postgresql;
using FindMembers = Marten.Linq.Parsing.FindMembers;
namespace Marten.Events.Projections.Flattened;
@@ -26,7 +27,7 @@ public partial class FlatTableProjection: GeneratedProjection, IProjectionSchema
private readonly string _inlineTypeName;
public FlatTableProjection(string tableName, SchemaNameSource schemaNameSource): this(
- new DbObjectName("public", tableName), schemaNameSource)
+ new PostgresqlObjectName("public", tableName), schemaNameSource)
{
}
diff --git a/src/Marten/Events/Projections/Flattened/StatementMap.cs b/src/Marten/Events/Projections/Flattened/StatementMap.cs
index 9de456a2c4..62e268d1a3 100644
--- a/src/Marten/Events/Projections/Flattened/StatementMap.cs
+++ b/src/Marten/Events/Projections/Flattened/StatementMap.cs
@@ -8,6 +8,7 @@
using Marten.Events.CodeGeneration;
using Marten.Internal.CodeGeneration;
using Weasel.Core;
+using Weasel.Postgresql;
using Weasel.Postgresql.Tables;
namespace Marten.Events.Projections.Flattened;
@@ -42,7 +43,7 @@ bool IEventHandler.AssertValid(EventGraph events, out string? message)
IEnumerable IEventHandler.BuildObjects(EventGraph events, Table table)
{
var functionName = $"mt_upsert_{table.Identifier.Name}_{typeof(T).NameInCode().Sanitize()}";
- _functionIdentifier = new DbObjectName(table.Identifier.Schema, functionName);
+ _functionIdentifier = new PostgresqlObjectName(table.Identifier.Schema, functionName);
yield return new FlatTableUpsertFunction(_functionIdentifier, table, _columnMaps);
}
diff --git a/src/Marten/Events/Schema/EventProgressionTable.cs b/src/Marten/Events/Schema/EventProgressionTable.cs
index ed0ffc428a..fc5694dbd8 100644
--- a/src/Marten/Events/Schema/EventProgressionTable.cs
+++ b/src/Marten/Events/Schema/EventProgressionTable.cs
@@ -1,11 +1,12 @@
using Weasel.Core;
+using Weasel.Postgresql;
using Weasel.Postgresql.Tables;
namespace Marten.Events.Schema;
internal class EventProgressionTable: Table
{
- public EventProgressionTable(string schemaName): base(new DbObjectName(schemaName, "mt_event_progression"))
+ public EventProgressionTable(string schemaName): base(new PostgresqlObjectName(schemaName, "mt_event_progression"))
{
AddColumn("name").AsPrimaryKey();
AddColumn("last_seq_id", "bigint").AllowNulls();
diff --git a/src/Marten/Events/Schema/EventsTable.cs b/src/Marten/Events/Schema/EventsTable.cs
index 0947653eab..d424b822f6 100644
--- a/src/Marten/Events/Schema/EventsTable.cs
+++ b/src/Marten/Events/Schema/EventsTable.cs
@@ -13,7 +13,7 @@ namespace Marten.Events.Schema;
internal class EventsTable: Table
{
- public EventsTable(EventGraph events): base(new DbObjectName(events.DatabaseSchemaName, "mt_events"))
+ public EventsTable(EventGraph events): base(new PostgresqlObjectName(events.DatabaseSchemaName, "mt_events"))
{
AddColumn(new EventTableColumn("seq_id", x => x.Sequence)).AsPrimaryKey();
AddColumn(new EventTableColumn("id", x => x.Id)).NotNull();
@@ -40,7 +40,7 @@ public EventsTable(EventGraph events): base(new DbObjectName(events.DatabaseSche
{
ColumnNames = new[] { "stream_id", TenantIdColumn.Name },
LinkedNames = new[] { "id", TenantIdColumn.Name },
- LinkedTable = new DbObjectName(events.DatabaseSchemaName, "mt_streams")
+ LinkedTable = new PostgresqlObjectName(events.DatabaseSchemaName, "mt_streams")
});
Indexes.Add(new IndexDefinition("pk_mt_events_stream_and_version")
@@ -54,7 +54,7 @@ public EventsTable(EventGraph events): base(new DbObjectName(events.DatabaseSche
{
ColumnNames = new[] { "stream_id" },
LinkedNames = new[] { "id" },
- LinkedTable = new DbObjectName(events.DatabaseSchemaName, "mt_streams"),
+ LinkedTable = new PostgresqlObjectName(events.DatabaseSchemaName, "mt_streams"),
OnDelete = CascadeAction.Cascade
});
diff --git a/src/Marten/Events/Schema/StreamsTable.cs b/src/Marten/Events/Schema/StreamsTable.cs
index 78f76a92dd..551292af72 100644
--- a/src/Marten/Events/Schema/StreamsTable.cs
+++ b/src/Marten/Events/Schema/StreamsTable.cs
@@ -21,7 +21,7 @@ internal class StreamsTable: Table
{
public const string TableName = "mt_streams";
- public StreamsTable(EventGraph events): base(new DbObjectName(events.DatabaseSchemaName, TableName))
+ public StreamsTable(EventGraph events): base(new PostgresqlObjectName(events.DatabaseSchemaName, TableName))
{
var idColumn = events.StreamIdentity == StreamIdentity.AsGuid
? new StreamTableColumn("id", x => x.Id)
diff --git a/src/Marten/MartenRegistry.cs b/src/Marten/MartenRegistry.cs
index 9e2b7fdb05..6d0f5103c6 100644
--- a/src/Marten/MartenRegistry.cs
+++ b/src/Marten/MartenRegistry.cs
@@ -14,6 +14,7 @@
using Marten.Storage.Metadata;
using NpgsqlTypes;
using Weasel.Core;
+using Weasel.Postgresql;
using Weasel.Postgresql.Tables;
using FindMembers = Marten.Linq.Parsing.FindMembers;
@@ -453,7 +454,7 @@ public DocumentMappingExpression ForeignKey(Expression> expre
var foreignKey =
new ForeignKey($"{m.TableName.Name}_{duplicateField.ColumnName}_fkey")
{
- LinkedTable = new DbObjectName(schemaName ?? m.DatabaseSchemaName, tableName),
+ LinkedTable = new PostgresqlObjectName(schemaName ?? m.DatabaseSchemaName, tableName),
ColumnNames = new[] { duplicateField.ColumnName },
LinkedNames = new[] { columnName }
};
diff --git a/src/Marten/Schema/DocumentMapping.cs b/src/Marten/Schema/DocumentMapping.cs
index 4cd4dc2519..f356404547 100644
--- a/src/Marten/Schema/DocumentMapping.cs
+++ b/src/Marten/Schema/DocumentMapping.cs
@@ -146,7 +146,8 @@ public MemberInfo IdMember
public Type DocumentType { get; }
- public virtual DbObjectName TableName => new(DatabaseSchemaName, $"{SchemaConstants.TablePrefix}{_alias}");
+ public virtual DbObjectName TableName =>
+ new PostgresqlObjectName(DatabaseSchemaName, $"{SchemaConstants.TablePrefix}{_alias}");
public DocumentMetadataCollection Metadata { get; }
@@ -158,10 +159,17 @@ public MemberInfo IdMember
public SubClasses SubClasses { get; }
- public DbObjectName UpsertFunction => new(DatabaseSchemaName, $"{SchemaConstants.UpsertPrefix}{_alias}");
- public DbObjectName InsertFunction => new(DatabaseSchemaName, $"{SchemaConstants.InsertPrefix}{_alias}");
- public DbObjectName UpdateFunction => new(DatabaseSchemaName, $"{SchemaConstants.UpdatePrefix}{_alias}");
- public DbObjectName OverwriteFunction => new(DatabaseSchemaName, $"{SchemaConstants.OverwritePrefix}{_alias}");
+ public DbObjectName UpsertFunction =>
+ new PostgresqlObjectName(DatabaseSchemaName, $"{SchemaConstants.UpsertPrefix}{_alias}");
+
+ public DbObjectName InsertFunction =>
+ new PostgresqlObjectName(DatabaseSchemaName, $"{SchemaConstants.InsertPrefix}{_alias}");
+
+ public DbObjectName UpdateFunction =>
+ new PostgresqlObjectName(DatabaseSchemaName, $"{SchemaConstants.UpdatePrefix}{_alias}");
+
+ public DbObjectName OverwriteFunction =>
+ new PostgresqlObjectName(DatabaseSchemaName, $"{SchemaConstants.OverwritePrefix}{_alias}");
public string DatabaseSchemaName
{
diff --git a/src/Marten/Schema/Identity/Sequences/HiLoSequence.cs b/src/Marten/Schema/Identity/Sequences/HiLoSequence.cs
index 61f1c64791..acc1c8e1ea 100644
--- a/src/Marten/Schema/Identity/Sequences/HiLoSequence.cs
+++ b/src/Marten/Schema/Identity/Sequences/HiLoSequence.cs
@@ -30,7 +30,7 @@ public HiloSequence(IMartenDatabase database, StoreOptions options, string entit
_settings = settings;
}
- private DbObjectName GetNextFunction => new(_options.DatabaseSchemaName, "mt_get_next_hi");
+ private DbObjectName GetNextFunction => new PostgresqlObjectName(_options.DatabaseSchemaName, "mt_get_next_hi");
public string EntityName { get; }
diff --git a/src/Marten/Schema/Identity/Sequences/SequenceFactory.cs b/src/Marten/Schema/Identity/Sequences/SequenceFactory.cs
index 2377d180f0..d83af4a090 100644
--- a/src/Marten/Schema/Identity/Sequences/SequenceFactory.cs
+++ b/src/Marten/Schema/Identity/Sequences/SequenceFactory.cs
@@ -6,6 +6,7 @@
using Marten.Storage;
using Weasel.Core;
using Weasel.Core.Migrations;
+using Weasel.Postgresql;
using Weasel.Postgresql.Tables;
namespace Marten.Schema.Identity.Sequences;
@@ -33,7 +34,7 @@ public ISchemaObject[] Objects
{
get
{
- var table = new Table(new DbObjectName(_options.DatabaseSchemaName, "mt_hilo"));
+ var table = new Table(new PostgresqlObjectName(_options.DatabaseSchemaName, "mt_hilo"));
table.AddColumn("entity_name").AsPrimaryKey();
table.AddColumn("hi_value").DefaultValue(0L);
diff --git a/src/Marten/Storage/SystemFunction.cs b/src/Marten/Storage/SystemFunction.cs
index c14f98bd77..9b49444568 100644
--- a/src/Marten/Storage/SystemFunction.cs
+++ b/src/Marten/Storage/SystemFunction.cs
@@ -1,6 +1,7 @@
using System.IO;
using Marten.Schema;
using Weasel.Core;
+using Weasel.Postgresql;
using Weasel.Postgresql.Functions;
namespace Marten.Storage;
@@ -15,7 +16,7 @@ public SystemFunction(StoreOptions options, string functionName, string args, bo
}
public SystemFunction(string schema, string functionName, string args, bool isRemoved = false)
- : base(new DbObjectName(schema, functionName))
+ : base(new PostgresqlObjectName(schema, functionName))
{
IsRemoved = isRemoved;
_args = args;