Skip to content

Only reset embedded Central DB schema on a genuinely uninitialized schema and fix merge conflict issue - #211

Merged
Mark7625 merged 3 commits into
OpenRune:mainfrom
jelqscape:fix-central-embedded-db-wipe
Sep 4, 2026
Merged

Only reset embedded Central DB schema on a genuinely uninitialized schema and fix merge conflict issue#211
Mark7625 merged 3 commits into
OpenRune:mainfrom
jelqscape:fix-central-embedded-db-wipe

Conversation

@jelqscape

Copy link
Copy Markdown
Contributor

Summary

CentralEmbeddedLifecycle.startIfConfigured caught any Throwable from Central's embedded startup and unconditionally ran DROP SCHEMA public CASCADE against the embedded Postgres DB, treating every startup failure as schema corruption. A plain port-bind conflict (or any other unrelated startup failure) took the same "wipe the whole database" path as an actually corrupted/uninitialized schema - not scoped to the case the comment (// Dev recovery) claims it's for.

Fix

Narrowed the reset to only fire when the failure's cause chain contains a SQLException whose SQLSTATE indicates Central's expected tables genuinely don't exist yet:

  • 42P01 - undefined_table
  • 42703 - undefined_column
  • 3F000 - invalid_schema_name

Everything else (bind conflicts, generic runtime errors, unrelated SQL errors like connection-refused) now just propagates and fails startup normally, without touching the database.

The classification logic (CentralStartupFailure.indicatesUninitializedSchema) is pulled out into its own object so it's testable without standing up the lifecycle's real dependencies.

Also included

main's npcs.toml currently fails buildCache outright - a recent PR dropped the [[npc]] separator before an existing NPC block, so TOML parsing merged the two entries and crashed on decode (params key 'id' must be an integer param id). Fixed alongside this since it was blocking any fresh build/test of the actual Central fix.

Testing

  • Added CentralStartupFailureTest: verifies a bind conflict, an unrelated exception, and an unrelated SQL error (connection-refused) do not trigger a reset; verifies all three genuine uninitialized-schema SQLSTATEs do, both wrapped and unwrapped.
  • Booted the server locally with the fix in place - Central starts cleanly online, no reset/schema-drop log lines, matching normal behavior.
  • Tried reproducing a real port-bind conflict live first, but Netty/ktor's bind tolerated an already-held socket in local testing, so verification went through the unit tests above instead of a live repro.

🤖 Generated with Claude Code

PR OpenRune#204 (Demonic gorillas) dropped the [[npc]] header before the
pre-existing saltfish NPC block, so its id/inherit/contentGroup/
moveRestrict/wanderRange keys got parsed as part of the previous entry's
[npc.params] table instead. buildCache failed outright as a result
(ParamSerializer expects every params key to be an integer param id).
…zed schema

CentralEmbeddedLifecycle.startIfConfigured caught any Throwable from
Central's startup and unconditionally dropped the entire public schema
of the embedded Postgres DB, treating every failure as schema corruption.
A plain port-bind conflict (or any other unrelated startup failure) took
the same DROP SCHEMA public CASCADE path as a real missing schema.

Narrowed the reset to only fire when the exception's cause chain contains
a SQLException whose SQLSTATE indicates Central's tables genuinely don't
exist yet: 42P01 (undefined_table), 42703 (undefined_column), 3F000
(invalid_schema_name). Everything else now propagates and fails startup
without touching the database, matching the reported port-conflict case.

Moved the classification logic into a standalone CentralStartupFailure
object so it's testable without standing up the lifecycle's real
dependencies; CentralStartupFailureTest covers the bind-conflict case,
an unrelated exception, an unrelated SQL error, and all three genuine
uninitialized-schema SQLSTATEs (wrapped and unwrapped).
@jelqscape jelqscape changed the title Only reset embedded Central DB schema on a genuinely uninitialized schema Only reset embedded Central DB schema on a genuinely uninitialized schema and fix merge conflict issue Sep 4, 2026
@Mark7625
Mark7625 merged commit c04df82 into OpenRune:main Sep 4, 2026
3 checks passed
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.

2 participants