Schema Changes

Events happening in the community are now at Drupal community events on www.drupal.org.
karens's picture

There is no real 'announcement' system for CCK developers, so hopefully everyone who maintains a CCK module is subscribed to this group and will see this item. I want to forewarn everyone that we are about to make changes to the tablenames for CCK due to a new problem that emerged in 5.x with user-configurable content types. The problem is that our current system is to create a table for each content type called 'node_example' where 'example' is the name of the content type. In 4.7, all CCK-created content type names were prefixed with 'content_', so that table always looked like 'node_content_example', which always created a unique table name. In 5.x, you can give any name you like to a content type and it no longer has the 'content_' prefix, so someone could create a content type called, for instance, 'access' that would have created a CCK table called 'node_access', and, of course, there is already a node_access table, and it's one we don't want to alter!

So the table names will need to change, at least in 5.x. There is a thread where we are working on a patch that will probably be committed very soon (http://drupal.org/node/105787).

This will not affect any modules that have been using the API for table names, but any module that tries to explicitly use the table names used in the past is going to have problems.

The correct way to get table names is to use the API. There is a function content_database_info($field) that will return an array with a value for 'table'. This will have the correct tablename irregardless of whether the field is stored in per content type or per field tables, and will have the correct value both before and after table names are altered.

This change is also going to require a database update, so be sure to run update.php when you update to the latest versions of CCK.

If anyone starts getting mysql errors that indicate a non-existant table, this is likely to be the source of the problems.

Comments

Testers welcome

yched's picture

The changes Karen mentions above have been committed to 5.0--1.x (dev) branch : http://drupal.org/cvs?commit=53104
A new release (1.3) will be tagged in a day or two.

However, as the patch related to some central parts of cck, any amount of testing we could get before actually releasing is more than welcome.
Not many visible changes to test (apart from the neat 'teasers / full page display settings' if you haven't got them yet), we should just make sure that nothing breaks.

error in file currently in cvs

victorkane's picture

Since this relates to a typo in the cvs files, I didn't file it as an issue.

Upon copying the current cvs files into a test site with heavy use of cck (about 10,000 records), upon running update.php, I got the following error:

Parse error: syntax error, unexpected T_FUNCTION in /...path_to_module.../cck/content.install on line 10

I changed

<?php// $Id: content.install,v 1.28 2007/01/26 12:58:45 karens Exp $

to
<?php // $Id: content.install,v 1.28 2007/01/26 12:58:45 karens Exp $

I was then able to run the upgrade script successfully:

content module
Update #1002

    * ALTER TABLE {node_field_instance} ADD COLUMN display_settings mediumtext NOT NULL

Update #1003

    * RENAME TABLE {node_blog} TO {content_type_blog}
    * RENAME TABLE {node_book} TO {content_type_book}
    * RENAME TABLE {node_contacto} TO {content_type_contacto}
    * RENAME TABLE {node_curso} TO {content_type_curso}
    * RENAME TABLE {node_cursoprograma} TO {content_type_cursoprograma}
    * RENAME TABLE {node_empresa} TO {content_type_empresa}
    * RENAME TABLE {node_page} TO {content_type_page}
    * RENAME TABLE {node_project_issue} TO {content_type_project_issue}
    * RENAME TABLE {node_project_project} TO {content_type_project_project}
    * RENAME TABLE {node_project_release} TO {content_type_project_release}
    * RENAME TABLE {node_reg_telef} TO {content_type_reg_telef}
    * RENAME TABLE {node_story} TO {content_type_story}
    * RENAME TABLE {node_data_field_empresa} TO {content_field_empresa}
    * RENAME TABLE {node_data_field_telfono} TO {content_field_telfono}
    * RENAME TABLE {node_data_field_e_mail} TO {content_field_e_mail}
    * RENAME TABLE {node_data_field_correo_electrnico} TO {content_field_correo_electrnico}
    * RENAME TABLE {node_data_field_contacto} TO {content_field_contacto}
    * RENAME TABLE {node_data_field_fecha_curso} TO {content_field_fecha_curso}
    * RENAME TABLE {node_data_field_asistentes_al_curso} TO {content_field_asistentes_al_curso}

Then, my views on these content types stopped working, with errors relating to table names.

So, I first reedited the views, that didn't help.

I then enabled the devel module (could have been anything), and hit submit (I suppose I could have done that without changing any module settings, and it would have refreshed the views), and that refreshed the views and after that everything worked OK.

The only errors I received after that was in one case where I make a manual query of my own, and this was corrected by following KarenS' excellent advice (use API to get table name) above.

Thanks,

Victor Kane

Victor Kane
http://awebfactory.com.ar

Additional tests

victorkane's picture

Theme files naming conventions (5.0 style) continue to work ok.
Able to do CRUD operations on content types with Administration interface ok.
Once I corrected table names in hard coded JOIN statements in my own hacking, no other errors reported.

Victor Kane
http://awebfactory.com.ar

Victor, lots of thanks for

yched's picture

Victor, lots of thanks for you feedback.
The line break error in content.install is now fixed.
BTW, this was present only in the cvs HEAD branch - may I strongly advise you - and anyone - to get the files in the DRUPAL-5 branch instead ?
HEAD is not where actual dev takes place, we commit to DRUPAL-5 and in theory should keep HEAD in sync, but we (I ?) have sometimes been caught forgetting to mirror the commits.
Plus, some work will start sooner or later on a rewriting / refactoring of several parts in CCK, and HEAD will then be in an 'experimental' state...

BTW, I tried to include an automatic update for views definitions in the update process, but obviously it is currently less than perfect. I'll try to investigate.

Update : the views should

yched's picture

Update : the views should now be updated smoothly after the cck tables get renamed.

The fix is committed in cvs, and should be available in the 5.0-1.x-dev tarball tomorrow.
Or meanwhile you can manually apply the fix :
in content.install, function content_update_1003 :
move the variable_set('content_schema_version', 1003); line above the // regenerate views comment.

Content Construction Kit (CCK)

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: