I have a custom migration and write tests for it. Custom migration has additional table implemented with hook_schema().
In my test I have two test methods and when running the second, I receive "Base table or view not found: 1146 Table 'drupal7.simpletest760869my_migrate_table'". I debugged and table exists but Migrate uses old databasePrefix of SimpleTest rather than new one. Considering previous error, I have simpletest760869 prefix for first test and simpletest589467 prefix for the second. All the table with the first prefix are removed on tearDown() so Migrate tries to select from deleted table.
I still don't know why Migrate uses old prefix. But I'm sure it's the issue of Migrate as long as I can reproduce it in the clean Migrate module.
To reproduce the problem, you can add the second test method (copy-paste existing and rename it) in tests/plugins/destinations/term.test e.g.
function testTermImport() { ...}
function testTermImportAgain() { ... }
I receive the error like this:
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'rue89.qa.simpletest760869migrate_example_wine_categories' doesn't exist: SELECT wc.categoryid AS categoryid, wc.name AS name, wc.details AS details, wc.category_parent AS category_parent, wc.ordering AS ordering, map.destid1 AS migrate_map_destid1, map.needs_update AS needs_update FROM {migrate_example_wine_categories} wc LEFT OUTER JOIN {migrate_map_winevariety} map ON categoryid = map.sourceid1 LEFT OUTER JOIN {migrate_message_winevariety} msg ON categoryid = msg.sourceid1 WHERE (type = :db_condition_placeholder_0) AND (map.sourceid1 IS NULL OR map.needs_update = 1) AND (msg.sourceid1 IS NULL) ORDER BY category_parent ASC; Array ( [:db_condition_placeholder_0] => variety ) in MigrateSourceSQL->rewind() (line 317 of /var/www/rue89.qa/sites/all/modules/migrate/plugins/sources/sql.inc).
Comments
Comment #1
mikeryanFixed for D7 - the static cache of the migration list didn't get cleared between invocations, so queries against the original prefixed tables remained, I changed it to use drupal_static() so the list does get cleared.
D6 has a similar problem, but not such a simple solution. That needs more work...
Comment #2
p0deje commentedI have updated Migrate from CVS and confirm that bug doesn't reproduce for Migrate tests.
Still, my tests still fail to work. In my module I implement hook_schema() for custom table.
Migration produces error on count() method in sql.inc:222. However, if I comment out
tests works fine.
I debugged $countQuery and it uses old database prefix. Still I have no idea where it forms and don't know how to fix this issue.
P.S. This happens in D7 version.
Comment #3
p0deje commentedCan you please give me some advice where to look in?
Comment #4
mikeryanSorry, there's not much more to offer. This works in the Migrate module's own tests - all I can say is try to replicate the setUp() function as closely as possible.