Skip to content

refactor: migrate functions from types to functions modules - #24

Merged
vistart merged 2 commits into
release/v1.0.0.dev10from
fix/move-functions-from-types
Apr 9, 2026
Merged

vistart merged 2 commits into
release/v1.0.0.dev10from
fix/move-functions-from-types

Conversation

@vistart

@vistart vistart commented Apr 9, 2026 •

Copy link
Copy Markdown
Contributor

Description

Refactors SQL function generation utilities by migrating them from types/ to functions/ directory, following the module responsibility separation principle.

Changes:

  • functions/text_search.py (new): Contains 14 text search functions (to_tsvector, to_tsquery, plainto_tsquery, phraseto_tsquery, websearch_to_tsquery, ts_matches, ts_matches_expr, ts_rank, ts_rank_cd, ts_headline, tsvector_concat, tsvector_strip, tsvector_setweight, tsvector_length)
  • functions/xml.py (new): Contains 4 XML functions (xmlparse, xpath_query, xpath_exists, xml_is_well_formed)
  • types/text_search.py: Removed functions, retained types (PostgresTsVector, PostgresTsQuery, etc.)
  • types/xml.py: Removed functions, retained types (PostgresXML)

Affected Files:

  • functions/text_search.py (new)
  • functions/xml.py (new)
  • functions/init.py (updated exports)
  • types/text_search.py (functions removed)
  • types/xml.py (functions removed)
  • types/init.py (removed function exports)
  • backend/init.py (updated import sources)
  • tests (updated imports)

Type of change

  • refactor: A code restructuring without behavior change
  • feat: A new feature
  • docs: Documentation only changes
  • perf: A code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • chore: Changes to the build process or auxiliary tools
  • ci: Changes to our CI configuration files and scripts
  • build: Changes that affect the build system or external dependencies
  • revert: Reverts a previous commit

Breaking Change

  • No
  • Yes

Applicable rhosocial-activerecord Version Range:

Related Repositories/Packages

  • python-activerecord (core package): Backend module import source changed
  • python-activerecord-testsuite: Tests using postgres backend may need import updates

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 [specify backend/DB versions].

Test Plan:

  • Verified with testsuite (1011 tests passed)
  • Test branch: postgres fix/move-functions-from-types vs core release/v1.0.0.dev20

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/<issue_number>.<type>.md).
  • I have verified that my changes do not introduce SQL injection vulnerabilities.
  • I have checked for potential performance regressions.

Additional Notes

  • Changelog fragment will be created after PR merge (internal type)
  • Test results: 1011 tests passed

Split responsibilities between types and functions modules for text search and XML:

**Text Search**
- Create: functions/text_search.py with SQL generation functions
- Moved functions (14 total):
  - to_tsvector, to_tsquery, plainto_tsquery, phraseto_tsquery, websearch_to_tsquery
  - ts_matches, ts_matches_expr, ts_rank, ts_rank_cd, ts_headline
  - tsvector_concat, tsvector_strip, tsvector_setweight, tsvector_length
- Retained in types/text_search.py: PostgresTsVector, PostgresTsQuery, and related classes

**XML**
- Create: functions/xml.py with SQL generation functions
- Moved functions (4 total): xmlparse, xpath_query, xpath_exists, xml_is_well_formed
- Retained in types/xml.py: PostgresXML class

**Module Updates**
- functions/__init__.py: Export all new text search and XML functions
- types/__init__.py: Remove function exports, keep only type exports
- backend/__init__.py: Update imports to use functions.text_search
- test_xml_types.py: Update to import functions from functions.xml

**Benefits**
- Clear separation of concerns: types for data structures, functions for SQL generators
- Better module organization following single responsibility principle
- Easier maintenance and discoverability of SQL generation utilities

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vistart vistart self-assigned this Apr 9, 2026
@vistart vistart added the bug Something isn't working label Apr 9, 2026
@codecov

codecov Bot commented Apr 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 49.43820% with 45 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.73%. Comparing base (408ac6b) to head (cd0674b).
⚠️ Report is 1 commits behind head on release/v1.0.0.dev10.

Files with missing lines Patch % Lines
...ord/backend/impl/postgres/functions/text_search.py 26.66% 44 Missing ⚠️
...ctiverecord/backend/impl/postgres/functions/xml.py 96.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@                   Coverage Diff                    @@
##           release/v1.0.0.dev10      #24      +/-   ##
========================================================
+ Coverage                 72.71%   72.73%   +0.02%     
========================================================
  Files                       119      121       +2     
  Lines                      6860     6867       +7     
  Branches                   1139     1139              
========================================================
+ Hits                       4988     4995       +7     
  Misses                     1470     1470              
  Partials                    402      402              
Flag Coverage Δ
postgres-18 72.73% <49.43%> (+0.02%) ⬆️
python-3.14 72.73% <49.43%> (+0.02%) ⬆️
unittests 72.73% <49.43%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud

sonarqubecloud Bot commented Apr 9, 2026

Copy link
Copy Markdown

@vistart
vistart merged commit 329a5c5 into release/v1.0.0.dev10 Apr 9, 2026
12 checks passed
@vistart vistart mentioned this pull request Apr 12, 2026
4 of 12 tasks
vistart added a commit that referenced this pull request Apr 12, 2026
* refactor: migrate functions from types to functions modules

Split responsibilities between types and functions modules for text search and XML:

**Text Search**
- Create: functions/text_search.py with SQL generation functions
- Moved functions (14 total):
  - to_tsvector, to_tsquery, plainto_tsquery, phraseto_tsquery, websearch_to_tsquery
  - ts_matches, ts_matches_expr, ts_rank, ts_rank_cd, ts_headline
  - tsvector_concat, tsvector_strip, tsvector_setweight, tsvector_length
- Retained in types/text_search.py: PostgresTsVector, PostgresTsQuery, and related classes

**XML**
- Create: functions/xml.py with SQL generation functions
- Moved functions (4 total): xmlparse, xpath_query, xpath_exists, xml_is_well_formed
- Retained in types/xml.py: PostgresXML class

**Module Updates**
- functions/__init__.py: Export all new text search and XML functions
- types/__init__.py: Remove function exports, keep only type exports
- backend/__init__.py: Update imports to use functions.text_search
- test_xml_types.py: Update to import functions from functions.xml

**Benefits**
- Clear separation of concerns: types for data structures, functions for SQL generators
- Better module organization following single responsibility principle
- Easier maintenance and discoverability of SQL generation utilities

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* chore: add changelog fragment for PR #24

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
@vistart
vistart deleted the fix/move-functions-from-types branch May 30, 2026 12:49
vistart added a commit that referenced this pull request Oct 11, 2026
…mn-contracts has merged

The testsuite's typed-column contracts landed in its own release branch
(#24), so the branch this repo installed them from is both stale and about to
be deleted. Point the testsuite dependency at `release/v1.0.0.dev17`, the same
release branch the core dependency already uses.

Contract content is identical -- the release tip is the merge of this branch,
not a rewrite -- so this changes only where the contracts come from, not what
they assert.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant