From 9802ac889fe1a12323be7df02f6c95e864bee7f5 Mon Sep 17 00:00:00 2001
From: Gordon Heydon <gordon@heydon.com.au>
Date: Sun, 23 Aug 2009 11:59:30 +1000
Subject: [PATCH] role_permission required to upgrade

---
 includes/update.inc           |    4 ++++
 modules/system/system.install |   40 +++++++++++++++++++++-------------------
 2 files changed, 25 insertions(+), 19 deletions(-)

diff --git includes/update.inc includes/update.inc
index 4878e7d..1eb4519 100644
--- includes/update.inc
+++ includes/update.inc
@@ -247,6 +247,10 @@ function update_fix_d7_requirements() {
     $schema['cache_path'] = drupal_get_schema_unprocessed('system', 'cache');
     $schema['cache_path']['description'] = 'Cache table used for path alias lookups.';
     db_create_table($ret, 'cache_path', $schema['cache_path']);
+    // Add the role_permisson table
+    $schema['role_permission'] = drupal_get_schema_unprocessed('user', 'role_permission');
+    db_create_table($ret, 'role_permission', $schema['role_permission']);
+    variable_set('update_d7_requirements', TRUE);
 
     // Add column for locale context.
     if (db_table_exists('locales_source')) {
diff --git modules/system/system.install modules/system/system.install
index d8c2e5e..0ad452b 100644
--- modules/system/system.install
+++ modules/system/system.install
@@ -1762,27 +1762,29 @@ function system_update_7006() {
 function system_update_7007() {
   $ret = array();
 
-  $schema['role_permission'] = array(
-    'fields' => array(
-      'rid' => array(
-        'type' => 'int',
-        'unsigned' => TRUE,
-        'not null' => TRUE,
+  if (!db_table_exists('role_permission')) {
+    $schema['role_permission'] = array(
+      'fields' => array(
+        'rid' => array(
+          'type' => 'int',
+          'unsigned' => TRUE,
+          'not null' => TRUE,
+        ),
+        'permission' => array(
+          'type' => 'varchar',
+          'length' => 64,
+          'not null' => TRUE,
+          'default' => '',
+        ),
+      ),
+      'primary key' => array('rid', 'permission'),
+      'indexes' => array(
+        'permission' => array('permission'),
       ),
-      'permission' => array(
-        'type' => 'varchar',
-        'length' => 64,
-        'not null' => TRUE,
-        'default' => '',
-      ),
-    ),
-    'primary key' => array('rid', 'permission'),
-    'indexes' => array(
-      'permission' => array('permission'),
-    ),
-  );
+    );
 
-  db_create_table($ret, 'role_permission', $schema['role_permission']);
+    db_create_table($ret, 'role_permission', $schema['role_permission']);
+  }
 
   // Copy the permissions from the old {permission} table to the new {role_permission} table.
   $result = db_query("SELECT rid, perm FROM {permission} ORDER BY rid ASC");
-- 
1.6.4.rc0.17.gd9eb0

