magento / magento/data-migration-tool
Delta rewrite URL CE step not using database prefix correctly (with fix)
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 339
- Forks
- 195
- PR merge metrics
- No merged PRs in 30d
Description
### Preconditions
1. Data Migration Completed to or from a site that uses a database prefix
2. Source prefix is different than destination prefix (or only one has a prefix)
### Steps to reproduce
1. Run Delta step after there have been some changes
### Expected result
1. Should run to completion as it did after migration
### Actual result
1. Stops at Rewrites step with error
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'catalog_url_rewrite_product_category' doesn't exist, query was: SELECT `catalog_url_rewrite_product_category`.* FROM `catalog_url_re
write_product_category` WHERE (url_rewrite_id = '9088576') AND (category_id = '27') AND (product_id = '727')
The code complained about does NOT use the prefix as set up in the config
Strangely the delta step had run successfully before so I assume this step is not always run
### Solution
My guess is that in the file `Migration/Step/UrlRewrite/Version191to2000Delta.php`, function `saveProductCategoryRecord` on line 150 the whole block needs a look
`
$select = $this->destination->getAdapter()->getSelect();
$select->from(Version191to2000::DESTINATION_PRODUCT_CATEGORY)
->where('url_rewrite_id = ?', $record->getValue('url_rewrite_id'))
->where('category_id = ?', $record->getValue('category_id'))
->where('product_id = ?', $record->getValue('product_id'));
if (!$this->destination->getAdapter()->loadDataFromSelect($select)) {
$this->destination->saveRecords(
$this->source->addDocumentPrefix(Version191to2000::DESTINATION_PRODUCT_CATEGORY),
[[
'url_rewrite_id' => $record->getValue('url_rewrite_id'),
'category_id' => $record->getValue('category_id'),
'product_id' => $record->getValue('product_id')
]],
true
);
}
`
- line 151 is not using `$this->source->addDocumentPrefix` and it should
- as the select object is `$this->destination` I assume it should be `$select->from($this->destination->addDocumentPrefix(Version191to2000::DESTINATION_PRODUCT_CATEGORY),'*')`
- after fixing this the next command then errors again, as it uses `$this->source->addDocumentPrefix` to insert into the destination, which fails if they are not the same.
so this is what it should be, I think?
`
$select->from($this->destination->addDocumentPrefix(Version191to2000::DESTINATION_PRODUCT_CATEGORY),'*')
->where('url_rewrite_id = ?', $record->getValue('url_rewrite_id'))
->where('category_id = ?', $record->getValue('category_id'))
->where('product_id = ?', $record->getValue('product_id'));
if (!$this->destination->getAdapter()->loadDataFromSelect($select)) {
$this->destination->saveRecords(
$this->destination->addDocumentPrefix(Version191to2000::DESTINATION_PRODUCT_CATEGORY),
[[
'url_rewrite_id' => $record->getValue('url_rewrite_id'),
'category_id' => $record->getValue('category_id'),
'product_id' => $record->getValue('product_id')
]],
true
);
}
`
**THEN you get a similar error for `saveCmsPageRewrites`**
I think
` $adapter->delete(Version191to2000::DESTINATION, "entity_type = 'cms-page'");`
needs document prefix too
See below for fixes successfully made on my one instance
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in Migration/Step/UrlRewrite/Version191to2000Delta.php, especially saveProductCategoryRecord and saveCmsPageRewrites, and trace how source and destination document prefixes are applied. Reproduce a Delta migration where the source and destination prefixes differ. Done means the Rewrites step completes without missing-table errors, including CMS page rewrites.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100