My Profile - Installation

In this installment we'll focus on the install and un-install routines for our My Profile module. The first article (Part 1) is located here.. Part 1 discusses the data structure, database table and class model (to store and retrieve our custom data).

The following code should be stored in a file listing called "my_profile.install"

. Our module's name is "My Profile".

function my_profile_install() {
function my_profile_uninstall() {
function my_profile_schema() {
  $schema['my_profile'] = array(
    'description' => 'The base table for my_profile.',
    'fields' => array(
      'id' => array(
        'description' => 'The primary identifier for a my_profile.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE),
      'uid' => array(
        'description' => 'Foreign Key to the User table',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0),
      'alias' => array(
        'description' => 'A short alias or name for this user',
        'type' => 'varchar',
        'length' => 80,
        'not null' => TRUE,
        'default' => ''),
    'indexes' => array(
      'user_uid'        => array('uid'),
    'unique keys' => array(
       'id'     => array('id')
    'primary key' => array('id'),
  return $schema;


We simply implement 3 methods: hook_schema defines our table structure, hook_install creates the table, hook_uninstall removes the table.

When a system administrator goes to the "Module" settings dialog. The system will show "My Profile" as an available module. The administrator enables the module which invokes my_profile_install. The un-install method is only run when an administrator decides to disable and then explicitly uninstall "My Profile".

The next post details how to make sure our custom content is saved. The uses completes the customized account registration form. We need to add code to save our custom data.