Skip to content

feat(postgres): Implement field and column mapping support - #2

Merged
vistart merged 7 commits into
release/v1.0.0.dev2from
feature/field-adapter-annotation
Dec 11, 2025
Merged

vistart merged 7 commits into
release/v1.0.0.dev2from
feature/field-adapter-annotation

Conversation

@vistart

@vistart vistart commented Dec 11, 2025 •

Copy link
Copy Markdown
Contributor

Description

This pull request introduces comprehensive support for field and column mapping within the rhosocial-activerecord-postgres backend. It includes implementation for annotated type adapters and direct backend tests, ensuring that custom column names and type conversions work seamlessly with PostgreSQL.

Related Issues

Proposed Changes

  • Full Support for Mapped Column Models: Enables the use of custom column names for model fields in PostgreSQL backend, allowing for flexible mapping between Python object fields and database column names.
  • Annotated Type Adapter Support: Implements the necessary infrastructure and specific PostgreSQL provider for Annotated type adapters, ensuring proper data conversion and validation for fields with custom types.
  • Enhanced Test Coverage:
    • Added column mapping tests and updated dependencies.
    • Included new test cases for field and column mapping to cover various scenarios.
  • Adjusted Schema for Timezone-Aware Datetime: Modified the test schema to correctly handle timezone-aware datetime values, ensuring accurate and consistent data processing.

Type of change

Please select all that apply:

  • feat: A new feature
  • test: Adding missing tests or correcting existing tests (for the new feature)
  • docs: Documentation only changes (if related to the new feature)
  • perf: A code change that improves performance (if part of the feature)
  • chore: Changes to the build process or auxiliary tools and libraries suchs as documentation generation (if related to the new feature)
  • ci: Changes to our CI configuration files and scripts (if related to the new feature)
  • build: Changes that affect the build system or external dependencies (if related to the new feature)
  • revert: Reverts a previous commit

Breaking Change

  • Yes
  • No

Applicable rhosocial-activerecord Version Range:
This change is compatible with rhosocial-activerecord version ==1.0.0.dev14.

Related Repositories/Packages

This change is dependent on the rhosocial-activerecord core library's v1.0.0.dev14 release, which introduced the core column mapping and annotated type adapter features.

Testing

  • I have added new tests to cover my changes.
  • I have updated existing tests to reflect my changes.
  • All existing tests pass.
  • This change has been tested on PostgreSQL backend.

Test Plan:
Ran pytest tests/rhosocial/activerecord_postgres_test/feature/ to verify field and column mapping, as well as annotated adapter functionality.

Checklist

  • My code follows the project's code style guidelines.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation (Docstrings, README.md, etc.).
  • My changes generate no new warnings.
  • I have added a Changelog fragment (changelog.d/2.added,fixed.md).
  • I have verified that my changes do not introduce SQL injection vulnerabilities.
  • I have checked for potential performance regressions.

Additional Notes

This feature brings rhosocial-activerecord-postgres up to date with the latest data modeling capabilities of the core library.

vistart and others added 6 commits December 4, 2025 09:59
- Adds the 	ype_adapter_tests.sql schema file for PostgreSQL.
- Adds the bridge test file 	est_type_adapter.py to integrate the generic type adapter tests from python-activerecord-testsuite.
- Implements the setup_type_adapter_model_and_schema and get_yes_no_adapter methods in 	ests/providers/basic.py for the PostgreSQL backend.
Introduces `testing.md` for the PostgreSQL backend, detailing its testing setup, integration with the shared test suite, and backend-specific testing practices.
Adapts content from the existing MySQL testing guide, ensuring consistency in documentation style and structure.
Provides clear instructions on PostgreSQL-specific dependencies (`psycopg`), scenario configuration (`postgres_scenarios.yaml`), and Docker setup.
Emphasizes the capability declaration process at backend instantiation and the importance of comprehensive test imports for compatibility.
Includes examples for PostgreSQL-specific features like JSONB operators and troubleshooting tips.
Corrects the schema definition for the 	ype_adapter_tests table in the PostgreSQL backend. The last_login column is now properly defined to store timezone-aware datetime values, resolving the 	est_optional_datetime_conversion failures. This ensures consistent handling of datetime types between application and PostgreSQL database.
Adds implementation for `setup_annotated_query_fixtures` in `tests/providers/query.py` for the PostgreSQL backend.
Creates `searchable_items.sql` schema adapted for PostgreSQL.
Introduces `test_annotated_adapter_queries.py` bridge file to run the new generic tests from the testsuite.
This enables testing of `Annotated` type adapters in query scenarios for the PostgreSQL backend.
This commit brings the PostgreSQL backend up to date with the latest testing requirements from the core testsuite, specifically for the new field-to-column mapping and type adapter features.

- Updated `tests/providers/basic.py` and `tests/providers/query.py` to implement the new required fixture setup methods (`setup_mapped_models`, `setup_mixed_models`, `setup_annotated_query_fixtures`).
- Added the necessary test "bridge" files (e.g., `test_field_column_mapping.py`, `test_annotated_adapter_queries.py`) to integrate the generic tests from the testsuite.
- Created PostgreSQL-specific versions of the schema files (`posts.sql`, `comments.sql`, etc.) required by the new test cases.
- Patched the `insert` and `async insert` methods in the `PostgresBackend` to accept the `column_mapping` argument and correctly handle `SERIAL` primary keys by omitting them from the INSERT statement when their value is None. This resolves the `NotNullViolation` errors.

With these changes, all tests in the `feature/basic` and `feature/query` directories now pass for the PostgreSQL backend.
Adds low-level backend tests for the column name mapping feature,
targeting both the synchronous and asynchronous PostgreSQL backends.

- Introduces `test_column_mapping_backend.py` and
  `test_async_column_mapping_backend.py` to validate `column_mapping` and
  `column_adapters` functionality directly against the backend.

Additionally, this commit modernizes the project's dependencies:
- Replaces separate `psycopg` and `psycopg-binary` packages with the
  consolidated `psycopg[binary]` dependency.
- Makes the `rhosocial-activerecord` core library an explicit
  dependency in `pyproject.toml` and `requirements.txt` for clarity and
  better dependency management.
@vistart
vistart merged commit 965836b into release/v1.0.0.dev2 Dec 11, 2025
@vistart
vistart deleted the feature/field-adapter-annotation branch December 14, 2025 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant