Add AdapterInterface dialect helpers and replace MySQL with Postgres SQL and other SQL like RDBS - #41129
Add AdapterInterface dialect helpers and replace MySQL with Postgres SQL and other SQL like RDBS#41129Genaker wants to merge 3 commits into
Conversation
…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>
|
Hi @Genaker. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
|
@magento run all tests |
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>
|
@magento run all tests |
|
Static LiveCodeTest fixes are on @magento run all tests |
|
@magento create issue |
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 UPDATEtext,UNIONof 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\Mysqland switches Magento call sites to those helpers (and to existing ones such asgetIfNullSql()/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 sameAdapterInterfacemethods onpdo_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_CONCATgetFieldSql()→FIELD()castToText()/castToNumeric()(no-op /CAST(… AS DECIMAL)on MySQL; other engines can map to::text/::numeric)createTableLike()→CREATE TABLE … LIKEcreateTemporaryTableFromSelect()→ existing MySQLCREATE TEMPORARY TABLE … ENGINE=innodb IGNORE (SELECT)Also:
Selectconstructor type-hint relaxed fromPdo\MysqltoZend_Db_Adapter_Abstractso a non-MySQLAdapterInterfacecan callselect().--db-engineis passed throughDbValidator/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):
bin/magento setup:upgrade— exit 0, no SQLSTATE.bin/magento indexer:reindex— all indexers complete (catalog price, stock, EAV, catalog rule, fulltext).WJ01) returns variants;GROUP_CONCAT/FIELD()call sites used by collection / search appliers.setup:install --db-engine=mysqlstill 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\Mysqlhelpers,TemporaryTableService, andBatchIteratorempty-batchminValueare in this PR.Adobe CLA: signed as required for submissions to https://github.com/magento/magento2.
Contribution checklist (*)
Resolved issues: