Skip to content

fix: auto-map cross-database column types in ColumnFactory#133

Merged
usernane merged 1 commit intomainfrom
dev
Apr 28, 2026
Merged

fix: auto-map cross-database column types in ColumnFactory#133
usernane merged 1 commit intomainfrom
dev

Conversation

@usernane
Copy link
Copy Markdown
Member

Summary

Auto-map column data types between database engines in ColumnFactory::create(). When a type is not natively supported by the target engine (e.g. DataType::TEXT on MSSQL), the factory now consults TypesMap::MAP to find the equivalent type automatically.

Motivation

DataType::TEXT and other MySQL-only types throw DatabaseException when used in MSSQL table definitions, making it impossible to write cross-database schemas. Fixes #132.

Changes

  • Added resolveDatatype() to ColumnFactory — looks up type mappings across all registered engines in TypesMap::MAP when the type is not native to the target engine. Scales to any number of engines.
  • Added getDefaultMappedSize() to ColumnFactory — provides sensible default sizes when an unsized type (e.g. text) maps to a sized type (e.g. nvarchar). Explicit sizes in the column definition always take precedence.
  • Added 11 test cases in MSSQLColumnTest for MySQL → MSSQL auto-mapping (text, mediumtext, blob variants, double, timestamp, explicit size preservation, native type passthrough).
  • Added 10 test cases in MySQLColumnTest for MSSQL → MySQL auto-mapping (bigint, binary, date, datetime2, money, nchar, nvarchar, time, varbinary, native type passthrough).

How to Test / Verify

Unit tests cover all type mappings in both directions:

php vendor/bin/phpunit -c tests/phpunit.xml --filter "testAutoMap|testNativeTypes|testAutoMapPreserves"

20 new tests, 47 assertions. Full suite: 606 tests, 0 regressions.

Breaking Changes and Migration Steps

None. Native types pass through unchanged. The auto-mapping only activates when a type is not in the target engine's supported list.

Checklist

  • I reviewed my own diff before requesting review
  • My commits follow Conventional Commits
  • The title of the pull request follows Conventional Commits
  • I added/updated tests (or explained why not)
  • I updated docs (if needed)
  • I ran lint/cs-fixer (if applicable)
  • I considered backward compatibility
  • I considered security

Related issues

Closes #132

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

❌ Patch coverage is 96.42857% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 74.26%. Comparing base (3eec245) to head (a8ec169).
⚠️ Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
WebFiori/Database/Factory/ColumnFactory.php 96.42% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #133      +/-   ##
============================================
+ Coverage     74.14%   74.26%   +0.12%     
- Complexity     2087     2101      +14     
============================================
  Files            53       53              
  Lines          5198     5223      +25     
============================================
+ Hits           3854     3879      +25     
  Misses         1344     1344              
Flag Coverage Δ
php-8.1 74.98% <96.29%> (+0.12%) ⬆️
php-8.2 74.76% <96.29%> (+0.12%) ⬆️
php-8.3 74.10% <96.42%> (+0.12%) ⬆️
php-8.4 74.10% <96.42%> (+0.12%) ⬆️
php-8.5 74.10% <96.42%> (+0.12%) ⬆️

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
Copy link
Copy Markdown

@usernane usernane merged commit a77f309 into main Apr 28, 2026
16 checks passed
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.

bug(mssql): DataType::TEXT not supported in MSSQL column builder

1 participant