5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Drupal】hook_update_N のリセット方法

Last updated at Posted at 2023-12-02

新機能のリリース・バグ改修では、hook_update_Nを実装することが多いですよね。
hook_update_Nは、「DB更新時に実行を行うものとされ、実行後にモジュールのバージョン情報がデータベースに刻まれる」という仕様があります。

そのため、実装の単体テストやデバッグをするにあたって工夫されている方もいるかと思います。

工夫例として...

  • Databaseのリストアを繰り返したり...
  • 都度、別のモジュールを実装してスクリプトを検証したり...

ちょっとそこまでするのは馬鹿らしいですよね。

そこで今回は、一度走らせた番号をリセットしてくれるDrushコマンドを紹介しようと思います。

リセット方法

drush php:eval "\Drupal::service('update.update_hook_registry')->setInstalledVersion('custom_module', 10002);"

上記のコマンドを実行すると、データベース内のモジュールのスキーマバージョンがリセットされます。

参考リンク

hook_upadte_N について

hook_update_Nは DataBaseの更新を行うものです。データベースの Contents や Config 等に変更をかけることが可能です。

関連

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?