Skip to content

fix: don't allow runtime schema drops outside Development#61

Merged
andregoepel merged 1 commit into
mainfrom
bugfix/schema-creation-mode
Jul 4, 2026
Merged

fix: don't allow runtime schema drops outside Development#61
andregoepel merged 1 commit into
mainfrom
bugfix/schema-creation-mode

Conversation

@andregoepel

Copy link
Copy Markdown
Owner

Closes #53 (F4 — Marten AutoCreate.All runs schema DDL at runtime).

What

  • AutoCreateSchemaObjects is now chosen by environment: AutoCreate.All in Development (fast inner loop, permits destructive rebuilds), AutoCreate.CreateOrUpdate (additive only — never drops or rewrites) everywhere else.
  • New AppFoundationOptions.SchemaCreation (AutoCreate?) lets a host override the default — most notably AutoCreate.None for a least-privilege deployment where the schema is provisioned out-of-band and the app's DB role has no DDL rights.

Why

AutoCreate.All lets Marten drop and rewrite schema objects at runtime to match code. That forces the running app's DB role to hold DDL privileges (against least-privilege) and risks data loss if the code/database shape diverges. Defaulting to CreateOrUpdate outside Development removes the destructive behavior while keeping zero-ops schema provisioning; the opt-in None supports a fully locked-down role with an explicit migration step (db-apply / a migration job / AddResourceSetupOnStartup).

Because of IntegrateWithWolverine(), the durable inbox/outbox tables are registered with Marten, so whichever mode is chosen also governs those tables.

Tests

AddAppFoundationSchemaCreationTests covers: non-Development → CreateOrUpdate, Development → All, and explicit SchemaCreation overriding the environment default.

Verification

AutoCreate.All lets Marten drop and rewrite schema objects at runtime to
match code, forcing the app's DB role to hold DDL rights and risking data
loss on a code/database mismatch.

Default AutoCreateSchemaObjects by environment instead: keep All for the
Development inner loop, but use CreateOrUpdate (additive only, never drops)
everywhere else. Add an AppFoundationOptions.SchemaCreation knob so a host
can override — e.g. AutoCreate.None for a least-privilege role with schema
provisioned out-of-band.

Closes #53
@andregoepel
andregoepel merged commit e84872b into main Jul 4, 2026
3 checks passed
@andregoepel
andregoepel deleted the bugfix/schema-creation-mode branch July 5, 2026 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security] Marten AutoCreate.All runs schema DDL at runtime (F4)

1 participant