Skip to content

Add first-class enum support#41

Open
BiqRed wants to merge 1 commit into
mr-fatalyst:mainfrom
BiqRed:feature/enum-types
Open

Add first-class enum support#41
BiqRed wants to merge 1 commit into
mr-fatalyst:mainfrom
BiqRed:feature/enum-types

Conversation

@BiqRed

@BiqRed BiqRed commented Jun 19, 2026

Copy link
Copy Markdown

Summary

This adds first-class support for string-valued Python enums across schema extraction, migrations, SQL rendering, and runtime value handling.

The migration layer now manages PostgreSQL enum types directly: it creates enum types before dependent tables, appends new enum values with ALTER TYPE, drops unused enum types, and emits a manual migration marker for destructive enum changes such as value removal or reorder. That keeps migration generation usable while making the unsafe step explicit in the generated file.

The query layer now keeps enum values typed as strings for binding, but adds PostgreSQL casts for enum columns and enum arrays. SQLite remains text-backed, while MySQL uses inline ENUM definitions in generated DDL.

Details

  • Detect string-valued Python Enum annotations, including optional fields and list enum arrays.
  • Support custom PostgreSQL enum type names through db_type, while preserving text overrides such as TEXT.
  • Serialize enum defaults and mutation values through their string values.
  • Add PostgreSQL enum casts for filters, IN lookups, inserts, updates, bulk paths, and enum arrays.
  • Generate PostgreSQL CREATE TYPE, DROP TYPE, and ALTER TYPE ADD VALUE statements.
  • Generate MySQL inline ENUM column definitions and append-value ALTER TABLE statements.
  • Replay enum value changes so future migrations see the correct schema state.
  • Add validation for enum values passed to update calls before building query IR.

Testing

  • cargo fmt --all --check
  • cargo test -p oxyde-codec -p oxyde-query -p oxyde-migrate -p oxyde-driver
  • maturin develop
  • python -m pytest python/oxyde/tests/unit
  • python -m pytest python/oxyde/tests/smoke python/oxyde/tests/integration
  • python -m ruff check on changed Python files
  • Manual end-to-end checks for migration generation and replay, SQLite enum CRUD, and dialect SQL rendering

@BiqRed BiqRed marked this pull request as ready for review June 19, 2026 15:27
@ebrake

ebrake commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Added a PR BiqRed#1 to preserve enum type hints for joined queries and enum arrays

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