From 61b8548f9ee89ffbdeb63e89400e03a57d94d034 Mon Sep 17 00:00:00 2001
From: Gordon Heydon <gordon@heydon.com.au>
Date: Mon, 20 Jul 2009 12:11:54 +1000
Subject: [PATCH 2/2] role_permission required to upgrade

To run the upgrade role permission is required right at the beginning and can't be added via the normal hook_update_n() process
---
 modules/system/system.install |   40 +++++++++++++++++++++-------------------
 update.php                    |    3 +++
 2 files changed, 24 insertions(+), 19 deletions(-)

diff --git modules/system/system.install modules/system/system.install
index c1ab41c..d4bfd59 100644
--- modules/system/system.install
+++ modules/system/system.install
@@ -1739,27 +1739,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");
diff --git update.php update.php
index 4c3f422..3d294bb 100644
--- update.php
+++ update.php
@@ -564,6 +564,9 @@ 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']);
+    
+    $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.
-- 
1.6.4.rc0.17.gd9eb0

