Skip to content

Marten attempts to recreate database on startup when DatabaseSchemaName is set to position #4069

@DawidHoppeVolue

Description

@DawidHoppeVolue

I've noticed a problem when a schema is named position (potentially other keywords might suffer from similar issue).

I created a small repro project - there's a dockerfile with db setup and a sample Marten app. When you run for the first time everything is fine - db gets created, async daemon runs. On second and every subsequent run, when async daemons attempts to run (it takes a while, I don't know why) it fails, because apparently it is trying to recreate existing database:

 Exception data:
          Severity: ERROR
          SqlState: 42P07
          MessageText: relation "pk_mt_events_stream_and_version" already exists
          File: index.c
          Line: 897
          Routine: index_create
         --- End of inner exception stack trace ---
         at Marten.StoreOptions.Weasel.Core.Migrations.IMigrationLogger.OnFailure(DbCommand command, Exception ex) in /_/src/Marten/StoreOptions.cs:line 306
         at Weasel.Postgresql.PostgresqlMigrator.executeDelta(SchemaMigration migration, DbConnection conn, AutoCreate autoCreate, IMigrationLogger logger, CancellationToken ct) in /_/src/Weasel.Postgresql/PostgresqlMigrator.cs:line 131
         at Weasel.Core.Migrations.DatabaseBase`1.executeMigration(ISchemaObject[] schemaObjects, CancellationToken ct) in /_/src/Weasel.Core/Migrations/DatabaseBase.cs:line 506
         at Weasel.Core.Migrations.DatabaseBase`1.executeMigration(ISchemaObject[] schemaObjects, CancellationToken ct) in /_/src/Weasel.Core/Migrations/DatabaseBase.cs:line 506
         at Weasel.Core.Migrations.DatabaseBase`1.generateOrUpdateFeature(Type featureType, IFeatureSchema feature, CancellationToken token, Boolean skipPostProcessing) in /_/src/Weasel.Core/Migrations/DatabaseBase.cs:line 485
         at Weasel.Core.Migrations.DatabaseBase`1.ensureStorageExistsAsync(IList`1 types, Type featureType, CancellationToken token) in /_/src/Weasel.Core/Migrations/DatabaseBase.cs:line 449
         at JasperFx.Events.Daemon.JasperFxAsyncDaemon`3.StartHighWaterDetectionAsync() in /_/src/JasperFx.Events/Daemon/JasperFxAsyncDaemon.cs:line 361
         at JasperFx.Events.Daemon.JasperFxAsyncDaemon`3.StartAgentAsync(String shardName, CancellationToken token) in /_/src/JasperFx.Events/Daemon/JasperFxAsyncDaemon.cs:line 165
         at Polly.ResiliencePipeline.<>c__2`1.<<ExecuteAsync>b__2_0>d.MoveNext()
      --- End of stack trace from previous location ---
         at Polly.Outcome`1.GetResultOrRethrow()
         at Polly.ResiliencePipeline.ExecuteAsync[TState](Func`3 callback, TState state, CancellationToken cancellationToken)
         at Marten.Events.Daemon.Coordination.ProjectionCoordinator.tryStartAgent(CancellationToken stoppingToken, IProjectionDaemon daemon, ShardName name, IProjectionSet set) in /_/src/Marten/Events/Daemon/Coordination/ProjectionCoordinator.cs:line 318

When you change DatabaseSchemaName in Program.cs:71 to some other value, like custom it works as expected. Postgres allow such schema name, so Marten should as well.

MartenMinimalRepro.zip

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions