2

I am wondering if it is safe to manually remove entries on the db_schema_whitelist.json file. I created a table called customer_address_relationship using the declarative schema approach and then I generated the db_schema_whitelist.json first and ran the php bin/magento setup:upgrade command. The generated db_schema_whitelist.json file had the following entries:

{
    "customer_address_relationship": {
        "column": {
            "entity_id": true,
            "customer_id": true,
            "address_id": true
        },
        "constraint": {
            "PRIMARY": true,
            "CSTR_ADDR_RELATIONSHIP_CSTR_ID_CSTR_ENTT_ENTT_ID": true,
            "CSTR_ADDR_RELATIONSHIP_ADDR_ID_CSTR_ADDR_ENTT_ENTT_ID": true
        }
    }
}

I then later decided to change my approach to the problem at hand and had to drop the customer_address_relationship table (by removing it from db_schema.xml and generating db_schema_whitelist.json again and then running setup:upgrade). The better approach was to add a column instead to an existing table called customer_address_entity after adding the column in my db_schema.xml and generating the db_schema_whitelist.json file, the content of the file was now as follows:

{
    "customer_address_relationship": {
        "column": {
            "entity_id": true,
            "customer_id": true,
            "address_id": true
        },
        "constraint": {
            "PRIMARY": true,
            "CSTR_ADDR_RELATIONSHIP_CSTR_ID_CSTR_ENTT_ENTT_ID": true,
            "CSTR_ADDR_RELATIONSHIP_ADDR_ID_CSTR_ADDR_ENTT_ENTT_ID": true
        }
    },
    "customer_address_entity": {
        "column": {
            "address_type": true
        }
    }
}

Since I no longer need the table customer_address_relationship. Is it safe to alter the generated db_schema_whitelist.json and remove its entries? What is the implication of this if there is any?

1 Answer 1

1

In the current dual state where tables and columns can be added/altered/removed either via setup scripts (those located in the Setup folder) or via the new etc/db_schema.xml files, Magento can not know by itself which tables/columns can be safely altered using only the db_schema.xml files. Hence, the db_schema_whitelist.json holds a list of all the DB tables, columns, indexes, constraints, etc that were created via declarative schema and can therefore be safely altered in case it detects any change for those elements in an upgraded db_schema.xml file. Hope it makes more sense now.

1
  • Thank you very much, this sure does make sense and it cleared a lot Commented Aug 3, 2021 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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