Skip to content

UserCore Refactor#2

Open
andromika wants to merge 66 commits intomasterfrom
refactor
Open

UserCore Refactor#2
andromika wants to merge 66 commits intomasterfrom
refactor

Conversation

@andromika
Copy link
Copy Markdown
Member

This pull request introduces a major refactor of user-related database schemas, splitting the legacy monolithic userdb collection into multiple focused collections. It also adds a Mongoose plugin to make .lean() the default for find/findOne queries, improving performance and memory usage. The changes are backward-compatible for now, with the legacy schema retained for migration purposes.

User schema refactor and new collections:

  • Split the legacy userdb schema into new, specialized collections: users_core, user_inventory, user_oauth, user_guilds, user_quests, user_analytics, and user_connections, each with its own schema and file. The main schema export (schemas.js) now exposes these new collections as the authoritative source for user data. (schemas.js, schemas/user_analytics.js, schemas/user_connections.js, [1] [2] [3]
  • The old monolithic user schema is now located in _legacy_users.js and is only used for fallback/shim purposes, with clear deprecation warnings. (schemas/_legacy_users.js, schemas/_legacy_users.jsR1-R375)
  • The userDB export in schemas.js now points to the legacy schema, while users and the new per-feature collections point to the split schemas. (schemas.js, schemas.jsL48-R73)

Query conventions and performance improvements:

  • Added a Mongoose plugin (leanDefaultPlugin.js) that makes .lean() the default for all find and findOne queries, unless explicitly opted out with { lean: false }. This reduces memory usage and improves query speed. (index.js, leanDefaultPlugin.js, [1] [2]

Code updates for new schema structure:

  • Updated references in other schemas to use the new split collections, e.g., user_inventory.js for achievements, and UsersCore for item operations, instead of the old userdb. (schemas/achievements.js, schemas/items.js, [1] [2]

Other:

  • Bumped package version to 0.19.0 to reflect these breaking and structural changes. (package.json, package.jsonL3-R3)

andromika and others added 30 commits March 6, 2026 14:02
Preserve the monolithic userdb schema as a legacy fallback.
This file will be the only reference to the old "userdb" collection
and is designed to be deleted when sunsetting is complete.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
New core user schema targeting the "users" collection (replacing the
monolithic "userdb"). Currencies live under currency.*, profile under
profile.*, and progression under progression.* per mongoscript spec.
Includes statics (get/set/getFull/new) matching the existing API.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extracts inventory and collectible data from the monolithic userdb into
a dedicated user_cosmetics collection. Includes ported addItem, removeItem,
modifyItems, hasItem, amtItem instance methods plus get/set/getFull/new statics.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ics, connections

Five new collection schemas completing the user data split:
- user_oauth: Discord/Patreon tokens and identity cache
- user_guilds: cached guild memberships (userId+guildId compound key)
- user_quests: per-quest progress tracking (userId+questId compound key)
- user_analytics: statistics and legacy metrics
- user_connections: third-party linked accounts (userId+type compound key)

All include appropriate indexes matching the mongoscript migration spec.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
DB.users now points to the new UsersCore model (collection "users").
New exports: userCosmetics, userOAuth, userGuilds, userQuests,
userAnalytics, userConnections. Legacy monolithic model available
as DB._legacyUserDB (deprecated) and DB.userDB (deprecated alias).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Virtual population paths now reference the "UsersCore" model name
(new "users" collection) instead of "UserDB" (legacy "userdb"). Also
updates marriageData localField to profile.featuredMarriage.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds interfaces for UserCore, UserCurrencies, UserProfile,
UserProgression, UserMeta, PrimeData, and all satellite document types
(UserCosmeticsData, UserOAuthData, UserGuildData, UserQuestData,
UserAnalyticsData, UserConnectionData) plus their Model interfaces.

Updates the Schemas interface to expose the new collections and marks
legacy User/UserModules/userDB types as deprecated.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Minor version bump signals the availability of the new split user
collections (users, user_cosmetics, user_oauth, user_guilds,
user_quests, user_analytics, user_connections) alongside the legacy
monolithic userdb.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…virtuals

- items.js: model("UserDB") → model("UsersCore"), modules.inventory → profile.inventory
- achievements.js: require users.js → user_cosmetics.js, modules.achievements → achievements
- virtuals.js: localField modules.inventory.id → profile.inventory.id

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
inventory lives in user_cosmetics collection, not in users.profile.
Moved the virtual from Users (UsersCore) to UserCosmetics with
localField: "inventory.id" matching the actual collection structure.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Rename collection, schema, model, and all TypeScript definitions
from UserCosmetics/userCosmetics to UserInventory/userInventory
to better reflect the collection's purpose.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant