Skip to content

refactor(db): centralize Postgres enum registration and reorganize OpenShockDb#316

Merged
hhvrc merged 7 commits into
developfrom
feature/pg-enum-refactor
Jul 1, 2026
Merged

refactor(db): centralize Postgres enum registration and reorganize OpenShockDb#316
hhvrc merged 7 commits into
developfrom
feature/pg-enum-refactor

Conversation

@hhvrc

@hhvrc hhvrc commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@hhvrc hhvrc self-assigned this Jun 13, 2026
Copilot AI review requested due to automatic review settings June 13, 2026 19:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 petTrainerpetrainer and 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 (petTrainerpetrainer) 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.

Comment thread Common/Utils/PgEnumAttribute.cs
Comment thread Common/OpenShockDb/Extensions/NpgsqlEnumExtensions.cs
Comment thread Common/Migrations/20260612142230_RefactorPgEnums.Designer.cs Outdated
Comment thread Common/Models/ShockerModelType.cs Outdated
…factor

# Conflicts:
#	Common/Migrations/OpenShockContextModelSnapshot.cs
#	Common/OpenShockDb/OpenShockContext.cs
@stage-review

stage-review Bot commented Jun 30, 2026

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 8 individual chapters for you:

Title
1 Define Postgres enum registration utilities
2 Move and consolidate database enums
3 Update database context and migrations
4 Update core models and logic
5 Update API controllers and models
6 Update LiveControlGateway and mappers
7 Update tests and test helpers
8 Other changes
Open in Stage

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.
@hhvrc hhvrc marked this pull request as draft July 1, 2026 00:08
@hhvrc hhvrc force-pushed the feature/pg-enum-refactor branch from 03c3288 to 84a8c1c Compare July 1, 2026 13:29
hhvrc added 3 commits July 1, 2026 15:39
…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.
@hhvrc hhvrc force-pushed the feature/pg-enum-refactor branch from 375ae00 to bc6f1bf Compare July 1, 2026 13:40
@hhvrc hhvrc marked this pull request as ready for review July 1, 2026 13:56
@hhvrc hhvrc changed the title refactor: Centralise Postgres enum registration and fix petTrainer typo refactor(db): centralize Postgres enum registration and reorganize OpenShockDb Jul 1, 2026
@hhvrc hhvrc merged commit 0f5c323 into develop Jul 1, 2026
22 checks passed
@hhvrc hhvrc deleted the feature/pg-enum-refactor branch July 1, 2026 14:02
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