refactor: split ensureSchemaImpl DDL into per-domain db/schema modules#2858
Merged
Conversation
…/schema modules Extract the ~1265-line inline DDL in ensureSchemaImpl() (server/lib/db.js) into per-domain modules under server/lib/db/schema/, each exporting a plain statement array; ensureSchemaImpl becomes a thin composer that runs buildUpgradeDdl() then buildCatalogDdl(). Statement text and order are byte-identical to the pre-split arrays (verified: 28 upgrade + 181 catalog statements match exactly), so the composed schema is unchanged. The catalog-DDL parity and catalogTypes text-scan tests now read the schema module sources (the DDL literals moved out of db.js). Mirrors the arcPlanner.js -> arcPlanner/* split (#1152). Closes #2832
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Splits the ~1265-line inline DDL in
ensureSchemaImpl()(server/lib/db.js) into per-domain modules underserver/lib/db/schema/, mirroring thearcPlanner.js→arcPlanner/*split from #1152.ensureSchemaImplbecomes a thin composer:Each domain module (
core,tribe,humanActivity,commissions,catalog,media,universes,library,pipeline,writersRoom,lora,privacy,audit) exports a plain statement array;db/schema/index.jsre-exports them and composes the two ordered lists.db.jsdrops from 1632 to 414 lines.No behavior change — byte-identical. The modules were extracted verbatim (statement text and order unchanged), so the composed schema is identical to the pre-split version. This was verified programmatically against the arrays from the parent commit: 28 upgrade + 181 catalog statements match exactly. Order is load-bearing (FK references, the
record_audit_log()function preceding its triggers, andcatalog_user_types' original post-media position) and is preserved by the composer.catalog_user_typeslives incatalog.jsas a separate export (catalogUserTypesDdl) because in the original array it sits after the media block, not adjacent to the other catalog tables — the composer threads it back into that exact position.The
db.catalogDdlParity.test.jsandcatalogTypes.test.jstext-scan tests now read the schema-module sources (the DDL literals moved out ofdb.js); their set/membership assertions are unchanged.New
db/schema/README.md(module catalog) anddb/schema/schema.test.js(composer contract: array shapes, compose order, FK-target-precedes-reference, function-before-triggers, audit-trigger pairs).Test plan
server/lib/db/schema/schema.test.js,db.catalogDdlParity.test.js,catalogTypes.test.js,db.guards.test.js,lib/index.test.js— all pass.portosDB (guard held). Zero failures.Closes #2832