refactor: Centralise Postgres enum registration and fix petTrainer typo#316
Open
hhvrc wants to merge 1 commit into
Open
refactor: Centralise Postgres enum registration and fix petTrainer typo#316hhvrc wants to merge 1 commit into
hhvrc wants to merge 1 commit into
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.
Comment on lines
+4
to
+6
| /// Marks an enum as a Postgres native enum type so it is automatically registered | ||
| /// with the EF Core model via <see cref="NpgsqlEnumExtensions.RegisterPgEnums"/>. | ||
| /// </summary> |
Comment on lines
+38
to
+40
| return new PgEnumInfo( | ||
| Map: b => b.MapEnum<TEnum>(pgTypeName), | ||
| Register: m => m.HasPostgresEnum(attr.Schema, pgTypeName, members)); |
| NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "password_encryption_type", new[] { "bcrypt_enhanced", "pbkdf2" }); | ||
| NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "permission_type", new[] { "shockers.use", "shockers.edit", "shockers.pause", "devices.edit", "devices.auth" }); | ||
| NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "role_type", new[] { "support", "staff", "admin", "system" }); | ||
| NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "shocker_model_type", new[] { "caiXianlin", "petTrainer", "petrainer998DR", "wellturnT330" }); |
Comment on lines
9
to
11
| [PgName("caiXianlin")] CaiXianlin = 0, | ||
| [PgName("petTrainer")] PetTrainer = 1, // Misspelled, should be "petrainer", | ||
| [PgName("petrainer")] PetTrainer = 1, | ||
| [PgName("petrainer998DR")] Petrainer998DR = 2, |
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.