Skip to content

Tables gone after migration when separate events schema added to store configuration #3975

Closed

Description

@tjdaniel

I had a "documents only" store before:

	public IDocumentStore DocumentStore { get; } = Marten.DocumentStore.For(_ =>
		{
			_.Connection(connectionString);

			_.AutoCreateSchemaObjects = isTestEnvironment ? AutoCreate.All : AutoCreate.None;
			_.DatabaseSchemaName = "my_store";

			_.UseNewtonsoftForSerialization(configure: options =>
			{
				options.DefaultValueHandling = DefaultValueHandling.Ignore;
			});

			_.Schema.Include<MyRegistry>();
		});

I added a separate events schema and diffed the schema with the Weasel methods:

	public IDocumentStore DocumentStore { get; } = Marten.DocumentStore.For(_ =>
		{
			_.Connection(connectionString);

			_.AutoCreateSchemaObjects = isTestEnvironment ? AutoCreate.All : AutoCreate.None;
			_.DatabaseSchemaName = "my_store";

			// Configure Event Store
			_.Events.DatabaseSchemaName = "my_events";

			_.UseNewtonsoftForSerialization(configure: options =>
			{
				options.DefaultValueHandling = DefaultValueHandling.Ignore;
			});

			_.Schema.Include<MyRegistry>();

			_.Events.AddEventType<PaymentAdviceImported>();
		});

...
	var migration = await documentStore.Storage.CreateMigrationAsync();
	var differences = migration.Deltas.Where(d => d.Difference != SchemaPatchDifference.None).ToList();

It recognizes the missing schema at the beginning, but the migration draws all current state from a single big read command where it tries to query all objects from both schemas. In my case there were 178 objects in the list of the to-be-compared objects. It also to checks objects from the new schema which obviously are not there, and the reader throws an exception (schema not found) and finishes work. The rest of the list still runs through and all remaining objects (even existing) are marked as non-existing. This blows all tables away that happen to be "after" any new schema objects in the comparison list (around 3/4 of my tables).

So as a workaround I create the schema before, but this is non-obvious.

This raises the question, why don't group the detection by schema?

Activity

  1. locked and limited conversation to collaborators on Oct 17, 2025
  2. converted this issue into a discussion #3979 on Oct 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions