I'm attempting to deploy a new permission and granting in a single update.
I have custom.module which defines a new permission with hook_permission
:
function custom_booking_permission() {
return array(
'custom allow registration' => array(
'title' => t('Fill out Registration Form'),
'description' => t('Allows a user to register their online account.'),
),
);
}
And then in the custom.install in hook_update_n
:
function custom_booking_update_7002() {
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('custom allow registration'));
}
The problem is that when I deploy this code and run drush updb -y
in my script, I get this error:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'module' cannot be null [error]
Which as I understand it is because Drupal has yet to recognise the new permission in hook_permission
.
I have other aspects to the update script such as enabling modules and reverting features, and then running drush updb
later in the script works fine. However I've always believed that drush updb
should be as early as possible. Maybe I just need to be more flexible.
Alternatively I was thinking about either an SQL insert to avoid the grant permission validation, or running a drush php-eval
later in the deployment script separate from drush updb
. Both strike me as undesirable.