In Magento 2, one of the XML configuration files a module may have is resources.xml file. For example, the sales module has one

#File: vendor/magento/module-sales/etc/resources.xml
<?xml version="1.0" encoding="UTF-8"?>
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/resources.xsd">
    <resource name="sales_setup" extends="core_setup" />
    <resource name="sales" extends="core" />

Does anyone know what these files are used for in Magento 2? They appear to be the old Magento 1 top level <resources/> node. However, since Magento no longer uses Setup Resource Model/Migrations (instead Magento 2 uses classes in Setup/InstallSchema.php, Setup/InstallData.php, Setup/UpgradeSchema.php, Setup/UpgradeData.php for install/migration-like scripts), its not 100% clear what the sales_setup resource is for.

For the non setup resource, is this just another way to add a database connection class with different credentials/connection string information? Or something else?

  • alan,Can please look at this file vendor\magento\framework\App\etc\resources.xsd"(4,41). may can be give any idea – Amit Bera May 4 '16 at 18:23
  • 1
    @AmitBera That tells how the data in resources.xml should appear, it doesn't tell us what the system uses these files for. – Alan Storm May 4 '16 at 18:28
  • Sorry, i did not have any clear idea about this .If i get any point then i will post – Amit Bera May 4 '16 at 18:49

I think the resources is relating to the actual database connection. M1 in the past had something like this:


so I would say the resources file is the successor to what the connection was.

Not sure that the _setup node provides much value above the other line as we have this code in


public function getConnectionName($resourceName)
    $connectionName = \Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION;

    $resourceName = preg_replace("/_setup$/", '', $resourceName);

and also in setup/src/Magento/Setup/Module/Setup/ResourceConfig.php

class ResourceConfig implements \Magento\Framework\App\ResourceConnection\ConfigInterface
     * {@inheritdoc}
    public function getConnectionName($resourceName)
        return \Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION;

I had a quick look through some of the enterprise modules to see if that sheds more light on the use of the resources.xml file (as multiple dbs is apparently an M2 Enterprise feature) but the only use that I have come across so far also only uses extends from core.

My hunch is that one would need to create additional db connections in app/etc/env.php which then allows you to use those values to override the ones shipped in the default resource.xml files (ie just the 1 default connection).

  • 2
    Just to summarize: 'resources.xml' allows extension developer to specify resource inheritance information and connection linking information. – Anton Kril May 12 '16 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.