4

Here is cleanetica_advanced.install file (of a "custom" module containing particulars of the site we work on):

<?php
function cleanetica_advanced_schema() {
  $schema['video'] = array (
    'description' => 'Videos with HTML titles',
    'fields' => array(
      'id' => array(
        'description' => 'Primary key for our table of videos',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'urlinfo' => array(
        'description' => 'The string referring to the video',
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE
      ),
      'title' => array(
        'description' => 'The title for a video, used in admin part only',
        'type' => 'text',
        'size' => 'medium',
        'not null' => TRUE
      ),
      'richtitle' => array(
        'description' => 'The HTML-formatted title for a video',
        'type' => 'text',
        'size' => 'medium',
        'not null' => TRUE
      ),
    ),
    'primary key' => array('id'),
  );

  return $schema;
}

function cleanetica_advanced_update_1(){
  drupal_install_schema('cleanetica_advanced');
}

I now think that it is better to create a separate module to manage 'video' database table and related things.

The trouble is that I have already created 'video' DB table. How to move/transfer a table into an other module?

1 Answer 1

1

The simplest way is to uninstall your existing module completely (not just disable), cut the schema definition from the old to the new, then enable both modules. The uninstall will remove the table, and the install will add it back in from the other module.

You'll also want to get rid of the cleanetica_advanced_update_1() function from your current module as that could cause some interesting inconsistencies if left unchecked.

3
  • This is not me who has written this module. I don't know consequences of its uninstalling and am afraid to do this. Is there an other way?
    – porton
    Feb 13, 2013 at 11:44
  • If you hadn't added the update function you'd be alright, but now that's there you're going to have to go directly into the system table and update the original's schema version back to 0, otherwise you'll get inconsistencies later on. Uninstalling is the clean way to do it, I wouldn't recommend the manual method unless you're totally confident of the changes you're making
    – Clive
    Feb 13, 2013 at 11:51
  • The only issue is that update function BTW. Install the video module before you move the schema over and it won't get overwritten, but will be known to Drupal from then on. Then you need to reset the schema to 0 for the original module, remove that update hook, and it should be fine. As always, test on a dev site first :)
    – Clive
    Feb 13, 2013 at 14:36

Your Answer

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

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