refactor(db): centralize Postgres enum registration and reorganize OpenShockDb#316
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR centralizes Postgres enum mapping/registration for EF Core by introducing a [PgEnum] marker attribute and shared registration helpers, while also correcting the petTrainer enum label typo to petrainer via a migration.
Changes:
- Added
[PgEnum]+MapPgEnums()/RegisterPgEnums()to centralize Npgsql enum mapping and EF model enum registration. - Updated multiple enums to use explicit
[PgName(...)]labels rather than relying on implicit enum member naming. - Added a migration to rename the Postgres enum value
petTrainer→petrainerand updated snapshots accordingly.
Reviewed changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| Common/Utils/PgEnumAttribute.cs | Adds a marker attribute to opt enums into centralized PG enum registration. |
| Common/OpenShockDb/UserNameBlacklist.cs | Marks MatchTypeEnum as a PG enum and sets explicit PG labels. |
| Common/OpenShockDb/OpenShockContext.cs | Replaces per-enum mapping/registration with centralized extension methods. |
| Common/OpenShockDb/NpgsqlEnumExtensions.cs | Implements centralized mapping/registration of all PG enums. |
| Common/OpenShockDb/ConfigurationItem.cs | Marks ConfigurationValueType as a PG enum and sets explicit PG labels. |
| Common/Models/ShockerModelType.cs | Fixes PG label typo for PetTrainer (petTrainer → petrainer) and opts into centralized registration. |
| Common/Models/RoleType.cs | Adds [PgEnum] and explicit PG labels. |
| Common/Models/PermissionType.cs | Adds [PgEnum] to ensure it’s included in centralized registration. |
| Common/Models/PasswordHashingAlgorithm.cs | Adds [PgEnum("password_encryption_type")] and explicit PG labels. |
| Common/Models/OtaUpdateStatus.cs | Adds [PgEnum] and explicit PG labels. |
| Common/Models/ControlType.cs | Adds [PgEnum] and explicit PG labels. |
| Common/Models/ControlLimitMode.cs | Adds [PgEnum] and explicit PG labels. |
| Common/Migrations/OpenShockContextModelSnapshot.cs | Updates model snapshot to reflect centralized enum definitions and renamed label. |
| Common/Migrations/20260612142230_RefactorPgEnums.Designer.cs | Adds migration designer snapshot for the refactor migration. |
| Common/Migrations/20260612142230_RefactorPgEnums.cs | Adds migration that renames the shocker_model_type value and updates enum annotations. |
Files not reviewed (1)
- Common/Migrations/20260612142230_RefactorPgEnums.Designer.cs: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…factor # Conflicts: # Common/Migrations/OpenShockContextModelSnapshot.cs # Common/OpenShockDb/OpenShockContext.cs
|
Ready to review this PR? Stage has broken it down into 8 individual chapters for you: Chapters generated by Stage for commit bc6f1bf on Jul 1, 2026 1:41pm UTC. |
Restamp RefactorPgEnums to run after AddEmailOutbox (resolving the merge ordering) and rewrite it to recreate each changed enum instead of relying on EF's annotation diff, which can only ALTER TYPE ... ADD VALUE and so silently no-ops reorders and leaves stale labels on renames. For each affected type the migration detaches its columns to text, drops the old type, remaps values, recreates the type, and reattaches: - control_type / password_encryption_type: reorder labels - shocker_model_type: rename labels to snake_case (cai_xianlin, petrainer, petrainer_998dr, wellturn_t330), fixing the petTrainer typo Verified both Up and Down round-trip against Postgres 15 with seeded data.
03c3288 to
84a8c1c
Compare
…enums Move entity classes into OpenShockDb/Models, key helpers into Keys/, queries into Queries/, and NpgsqlEnumExtensions into Extensions/. Relocate domain enums from Common/Models into OpenShockDb/Enums, add the missing DB enums (ConfigurationValueType, MatchTypeEnum, OtaUpdateStatus, PermissionType, RoleType), and split enum helper methods into dedicated *Extensions classes. Update all consumers to the new namespaces.
Remove now-unnecessary OpenShock.Common.Models usings, unqualify Models.Response.* references, and tidy up import ordering left over from the OpenShockDb reorganization.
Pass attr.Schema to MapEnum so schema-qualified Postgres enums are mapped in the correct schema instead of the default one, and fully-qualify the cref in PgEnumAttribute. Refresh OpenShockContextModelSnapshot after the enum/namespace changes.
375ae00 to
bc6f1bf
Compare
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.
No description provided.