Skip to content

Add AdapterInterface dialect helpers and replace MySQL with Postgres SQL and other SQL like RDBS - #41129

Open
Genaker wants to merge 3 commits into
magento:2.4-developfrom
Genaker:pgcompat-portable-sql
Open

Add AdapterInterface dialect helpers and replace MySQL with Postgres SQL and other SQL like RDBS#41129
Genaker wants to merge 3 commits into
magento:2.4-developfrom
Genaker:pgcompat-portable-sql

Conversation

@Genaker

@Genaker Genaker commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Description (*)

Magento core still embeds MySQL-only SQL (GROUP_CONCAT(), FIELD(), IFNULL() literals, backticks, CREATE TABLE … LIKE, CREATE TEMPORARY TABLE … ENGINE=… IGNORE (SELECT), ON DUPLICATE KEY UPDATE text, UNION of mixed types, UPDATE … LIMIT, SHOW VARIABLES LIKE 'version'). That is valid on MySQL and fatal on PostgreSQL.

This PR does not add a Postgres adapter. It adds dialect helpers on AdapterInterface / Pdo\Mysql and switches Magento call sites to those helpers (and to existing ones such as getIfNullSql() / quoteIdentifier() / insertOnDuplicate()).

The Postgres driver lives in a separate module: https://github.com/Genaker/postgento (fork of Kirill Morozov’s Morozov_PgCompat). That repo implements the same AdapterInterface methods on pdo_pgsql. Magento can review/test/merge this core PR on MySQL alone, and optionally install Postgento on a branch of this PR to run Magento on PostgreSQL. After this PR is in Magento, Postgento does not need the Magento SQL call-site patches.

The same change set is open for Mage-OS: mage-os/mageos-magento2#321

New adapter methods (MySQL implementations):

  • getGroupConcatSql()GROUP_CONCAT
  • getFieldSql()FIELD()
  • castToText() / castToNumeric() (no-op / CAST(… AS DECIMAL) on MySQL; other engines can map to ::text / ::numeric)
  • createTableLike()CREATE TABLE … LIKE
  • createTemporaryTableFromSelect() → existing MySQL CREATE TEMPORARY TABLE … ENGINE=innodb IGNORE (SELECT)

Also:

  • Select constructor type-hint relaxed from Pdo\Mysql to Zend_Db_Adapter_Abstract so a non-MySQL AdapterInterface can call select().
  • Setup --db-engine is passed through DbValidator / Installer::assertDbAccessible() so an optional engine can open the correct driver at install time. Default MySQL behavior is unchanged.

Behavior on MySQL is intended to be equivalent.

Related Pull Requests

Fixed Issues (if relevant)

N/A — no Magento issue filed yet.

Manual testing scenarios (*)

On a MySQL Magento Open Source install (this PR must not require Postgres):

  1. bin/magento setup:upgrade — exit 0, no SQLSTATE.
  2. bin/magento indexer:reindex — all indexers complete (catalog price, stock, EAV, catalog rule, fulltext).
  3. GraphQL: configurable product with variants (e.g. Luma WJ01) returns variants; GROUP_CONCAT / FIELD() call sites used by collection / search appliers.
  4. Storefront: homepage, category, PDP, cart, customer login.
  5. Admin: dashboard, catalog products, categories, EAV attributes, customers, CMS, indexers, sales orders.
  6. Guest checkout placing a Check / Money Order order (sales sequence + quote).
  7. Confirm setup:install --db-engine=mysql still validates and installs as today.

Optional Postgres: check out this PR, Composer-require https://github.com/Genaker/postgento (genaker/module-postgento), setup:install --db-engine=postgresql, then repeat indexer / GraphQL / storefront / admin / checkout.

Questions or comments

Happy to split adapter-interface methods vs call-site SQL into two PRs if that is easier to review. The adapter itself is Postgento — Magento can merge this PR first (MySQL-safe) and take Postgento as a Composer module whenever you want Postgres in the distribution.

Unit tests for the new Pdo\Mysql helpers, TemporaryTableService, and BatchIterator empty-batch minValue are in this PR.

Adobe CLA: signed as required for submissions to https://github.com/magento/magento2.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

…ll sites.

Lets a separate Postgres adapter implement the same helpers without Magento embedding GROUP_CONCAT, FIELD, backticks, or CREATE TABLE LIKE.

Co-authored-by: Cursor <cursoragent@cursor.com>
@m2-assistant

m2-assistant Bot commented Aug 18, 2026

Copy link
Copy Markdown

Hi @Genaker. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.
❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@Genaker

Genaker commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

@magento run all tests

@Genaker Genaker changed the title Add AdapterInterface dialect helpers and replace MySQL-only SQL Add AdapterInterface dialect helpers and replace MySQL with Postgres SQL and other SQL like RDBS Aug 18, 2026
Adobe 2.4-develop already differs from Mage-OS in several files; keep those Magento-only changes and describe the dialect helpers in Magento terms.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Genaker

Genaker commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

@magento run all tests

@Genaker

Genaker commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Static LiveCodeTest fixes are on 737e132d. Last Jenkins run was the previous SHA — re-running on HEAD.

@magento run all tests

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.

1 participant