event-sourcingevent-streamneventstore

EventStore 3.1 - SQL Persistence - How can I use a non-dbo schema?


For the project I'm working on, I can't use the [dbo] schema. From looking at the EventStore source, it doesn't look trivial to use a non-dbo schema.

So far, the best I've come up with is to use a custom dialect like this:

Example:

public override string AppendSnapshotToCommit
{
    get { return customizeSchema(_msSqlDialect.AppendSnapshotToCommit); }
}
private string customizeSchema(string dboStatement)
{
    // replace "[dbo]" with "[notdbo]", 
    // replace " Commits" with " [notdbo].Commits", 
    // replace " Snapshots" with " [notdbo].Snapshots"
}

I also have to customize the InitializeStorage property to replace "sysobjects" with "sys.objects" so I can add an additional constraint on the schema name.

This works, but it seems like there should be wireup options for customizing the schema and table names.

UsingSqlPersistence(...)
    .WithSchema(...)
    .WithCommitsTable(...)
    .WithSnapshotsTable(...)

Is there a clearly better way to handle this that I've missed?


Solution

  • While I can see a potential need to customize the table names, the existing version does not support that. All you need to do is to subclass the MsSqlDialect and then provide your custom version to the wireup like so:

    UsingSqlPersistence(...)
        .WithDialect(new MsSqlDialectWithCustomTableNames());