Looking at #420026: migrate_save_content_set() should update map table as necessary, it occurs to me a lot of things would be easier if the map table column names were consistent (i.e., always 'sourceid' and 'destid'). Also, introducing the reasonable restriction that a given view could only be the source for one content set would eliminate the need for the mcsid column in map tables, and the need to include the destination type in the map and message table names. So, I'm going to proceed with this refactoring. The update hook should fix up any existing tables, but custom views involving these tables will be affected, so heads up...

Comments

mikeryan’s picture

Status: Active » Fixed

Done. If you update an existing installation, you will need to update any code or custom views referencing the map and/or message tables to reflect their new names (destination - e.g., 'node' or 'user' - removed from the table name) and the map table fields names (now just 'sourceid' and 'destid').

robertdouglass’s picture

This must have been a precursor to this one? http://drupal.org/node/463830

mikeryan’s picture

Yes, my next priority for migrate module work (after the issue I'm about to open:-) will be to handle #463830: Support non-integer keys in sources and #420026: migrate_save_content_set() should update map table as necessary, those will be quite a bit easier with the refactoring.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

frankcarey’s picture

just a note: This update (6000) was timing out for me after 90 seconds. I had a quite a few content sets (10?) so that may be why, but still surprising.

Do the new map tables allow you to take advantage of views arguments to use the same view for multiple content sets?

i see you said "Also, introducing the reasonable restriction that a given view could only be the source for one content set would eliminate the need for the mcsid column in map tables, and the need to include the destination type in the map and message table names"

frankcarey’s picture

Status: Closed (fixed) » Active

I created a new content set and It looks like the map and msg table names are now being created using the mscid ("migrate_map_27"), so that in my mind would mean that YES, one view could be used as the basis for multiple content sets. This differs however from what update 6000 seemed to do because my existing map tables are all in the format "migrate_map_myviewname".

frankcarey’s picture

I'm getting a couple errors after saving my new content set:

* Could not analyze migrate_map_27 (connection default)
* Could not analyze migrate_msgs_27 (connection default)

Probably because the tables aren't being created.

mikeryan’s picture

Status: Active » Postponed (maintainer needs more info)

Your old tables should have been renamed to the migrate_map_mcsid format, it sounds like the failed update you had left things in an inconsistent state. At the time of update 6000, Table Wizard didn't have a $skip_analysis argument to tw_add_tables(), so if your map and message tables were large that would have been a problem.

Is there any more information you can give to help identify whether there's a current bug here? I don't know of any existing issues with managing the map and message tables...

frankcarey’s picture

For the new tables, I'm getting this error in my logs:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DEFAULT NULL, `level` INT unsigned NOT NULL DEFAULT 1, `message` MEDIUMTEXT NO' at line 3 query: update_sql /* admin : update_sql */ CREATE TABLE migrate_msgs_30 ( `mceid` INT unsigned NOT NULL auto_increment, `sourceid` DEFAULT NULL, `level` INT unsigned NOT NULL DEFAULT 1, `message` MEDIUMTEXT NOT NULL, PRIMARY KEY (mceid), INDEX sourceid (sourceid) ) /*!40100 DEFAULT CHARACTER SET UTF8 */ in /var/www/devroots/d6-matadortravel-com/includes/database.inc on line 529.

The query works if I re-run the query with INT for the type. Is it missing?

frankcarey’s picture

I think this is related to use of external tables only, because if i use a view based on a local table it seems to work fine. Looks like some lookup of the primary key's type is failing and not being passed in the query above?

frankcarey’s picture

Traced it back to the schema_mysql_inspect() call (aliased by a schema_invoke('inspect') call in migrate.module)

schema_mysql_inspect() looks up all the tables in the database. Since once the external tables are defined in hook_views_data() by tw as having a 'default' database, when the schema_mysql_inspect() get's called, it's not going to be one of the tables listed because it doesn't really exist in that database.

I'm thinking a small patch to this might check for presence of a period in the table name and then overwrite the table and database values and continue as normal.

frankcarey’s picture

OK, this is what i've got so far in migrate.module:

   $tablename = $view->base_table;
   // Tw can treat external mysql tables as internal, but we can revert
   // if we find a period in the tablename.
   if (strpos($tablename, '.')) {
     list($tabledb, $tablename) =  explode('.', $tablename);
   }
   $inspect = schema_invoke('inspect');
   db_set_active('default');
   $sourceschema = $inspect[$tablename];

But,I think the problem now is that $tabledb is the actual db name, not the alias from settings.php, so we'll have to get that back... driving on.

mikeryan’s picture

I cannot reproduce this in my environment using external tables. This looks funky:

Since once the external tables are defined in hook_views_data() by tw as having a 'default' database, when the schema_mysql_inspect() get's called, it's not going to be one of the tables listed because it doesn't really exist in that database.

The external tables should not be identified with the default database in hook_views_data() (specifically, _tw_generate_views_table_data()), they should have their true DB. I'm wondering if maybe your problems are related to #610128: Can't add external and internal tables' columns to the same view - I'm guessing you're running with your latest changes there. Can you try using the current CVS of Table Wizard and see if you still have problems with that?

Thanks.

frankcarey’s picture

Status: Fixed » Postponed (maintainer needs more info)

Yes, the problem was that i had some sort of hybrid code, and now the new functionality is showing up for me. RE #9 - #12: the patch in #661934: Allow migrate to handle external tables. is still needed to get external tables working (and the tw patch it depends on)

frankcarey’s picture

Status: Postponed (maintainer needs more info) » Fixed

Status: Postponed (maintainer needs more info) » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.