Skip to content

chore: Convert field_type from VARCHAR to PostgreSQL ENUM#8

Merged
xernobyl merged 4 commits intomainfrom
chore/refactor_type
Feb 2, 2026
Merged

chore: Convert field_type from VARCHAR to PostgreSQL ENUM#8
xernobyl merged 4 commits intomainfrom
chore/refactor_type

Conversation

@xernobyl
Copy link
Contributor

Summary

Converts the field_type column from VARCHAR to a PostgreSQL ENUM type, and implements a type-safe string-based enum in Go to ensure only valid field types can be used.

Changes

Database Schema

  • sql/001_initial_schema.sql: Updated to use field_type_enum instead of VARCHAR

Go Models (internal/models/feedback_records.go)

  • Added FieldType string-based enum type with constants
  • Implemented ValidFieldTypes map using map[FieldType]struct{} for efficient set membership checks
  • Added IsValid() and ParseFieldType() methods
  • Added UnmarshalJSON() for JSON validation
  • Updated structs to use FieldType instead of string:
    • FeedbackRecord.FieldType
    • CreateFeedbackRecordRequest.FieldType
    • ListFeedbackRecordsFilters.FieldType

Validation (internal/api/validation/validation.go)

  • Updated validateFieldType to use models.ParseFieldType() and ValidFieldTypes map
  • Added form decoder support for *FieldType in query parameters

OpenAPI Specification

  • Added enum values to field_type in response schema
  • Added enum values to field_type query parameter
  • Request schema already had correct enum values

Benefits

  • Type Safety: Compile-time and runtime validation ensures only valid field types
  • Data Integrity: PostgreSQL ENUM enforces constraints at database level
  • Better Documentation: OpenAPI spec clearly shows valid values
  • Performance: Efficient set membership checks using struct{} map values

@xernobyl xernobyl marked this pull request as ready for review February 2, 2026 11:30
@xernobyl xernobyl requested a review from mattinannt February 2, 2026 11:30
@xernobyl xernobyl enabled auto-merge February 2, 2026 11:30
Copy link
Member

@mattinannt mattinannt left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Looks good! :-)

@xernobyl xernobyl added this pull request to the merge queue Feb 2, 2026
Merged via the queue into main with commit 7e58936 Feb 2, 2026
5 checks passed
@xernobyl xernobyl deleted the chore/refactor_type branch February 2, 2026 14:43
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