You are here

function recipe_install in Recipe 5

Same name and namespace in other branches
  1. 6 recipe.install \recipe_install()
  2. 7.2 recipe.install \recipe_install()

File

./recipe.install, line 3

Code

function recipe_install() {
  $s = false;
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $s = db_query("CREATE TABLE {recipe} (\n         nid int(10) unsigned NOT NULL,\n         source varchar(255),\n         yield int(2) unsigned NOT NULL,\n         instructions text,\n         notes text,\n         preptime int(10) unsigned DEFAULT '0',\n         PRIMARY KEY (nid)\n      ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      $s = $s && db_query("CREATE TABLE {recipe_node_ingredient} (\n         id int unsigned NOT NULL PRIMARY KEY auto_increment,\n         nid int(10) unsigned NOT NULL,\n         unit_id int(3) unsigned NOT NULL,\n         quantity double,\n         ingredient_id int(10) unsigned NOT NULL\n      ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      $s = $s && db_query("CREATE TABLE {recipe_ingredient} (\n         id int(10) unsigned NOT NULL PRIMARY KEY auto_increment,\n         name varchar(255),\n         link int(10) NOT NULL\n      ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      $s = $s && db_query("CREATE TABLE {recipe_unit} (\n         id int(3) unsigned NOT NULL PRIMARY KEY auto_increment,\n         name varchar(64) NOT NULL default '',\n         abbreviation varchar(8) NOT NULL default '',\n         metric int(1) unsigned NOT NULL default '0',\n         type enum('Mass','Volume','Unit') NOT NULL default 'Mass'\n      ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      $s = $s && recipe_populate_units();
      break;
    case 'pgsql':
      $s = db_query("CREATE TABLE {recipe} (\n         nid integer NOT NULL,\n         source varchar(255),\n         yield integer NOT NULL,\n         instructions text,\n         notes text,\n         preptime integer NOT NULL default '0',\n         PRIMARY KEY (nid)\n      );");
      $s = $s && db_query("CREATE TABLE {recipe_node_ingredient} (\n         id serial NOT NULL,\n         nid integer NOT NULL,\n         unit_id integer NOT NULL,\n         quantity real,\n         ingredient_id integer NOT NULL,\n         PRIMARY KEY(id)\n      );");
      $s = $s && db_query("CREATE TABLE {recipe_ingredient} (\n         id serial NOT NULL PRIMARY KEY,\n         name varchar(255),\n         link integer not null\n      );");
      $s = $s && db_query("CREATE TABLE {recipe_unit} (\n         id serial NOT NULL PRIMARY KEY,\n         name varchar(64) NOT NULL default '',\n         abbreviation varchar(8) NOT NULL default '',\n         metric integer NOT NULL default '0',\n         type varchar(6) NOT NULL default 'Mass'\n      );");
      $s = $s && recipe_populate_units();
      break;
  }
  if ($s) {
    drupal_set_message(t('Recipe module installed tables successfully.'));
  }
  else {
    drupal_set_message(t('The installation of the Recipe module was unsuccessful.'), 'error');
  }
}