DDLTriggerInterface.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Framework\Setup\Declaration\Schema\Db;
  8. use Magento\Framework\Setup\Declaration\Schema\ElementHistory;
  9. /**
  10. * DDL triggers is events that can be fired:
  11. * - after element creation;
  12. * - before/after element modification
  13. * - before element removal
  14. *
  15. * Trigger is used to make changes in data not in schema, e.g migrate data from column of one table to
  16. * column of another table.
  17. *
  18. * Please note: triggers are used to serve needs of some operations, that can`t be described with declarative schema,
  19. * for example: renaming. Renaming implemented with removal column with old name and creating with new one.
  20. * Question with data is solved with help of triggers, that allows to migrate data.
  21. * This approach is correct from prospective of declaration but is not so fast as ALTER TABLE is.
  22. * So if you need to perform some renaming operations quickly, please use raw SQL dump instead, that can be taken with
  23. * help of --dry-run mode
  24. */
  25. interface DDLTriggerInterface
  26. {
  27. /**
  28. * Check whether current trigger can be applied to current statement.
  29. *
  30. * @param string $statement
  31. * @return bool
  32. */
  33. public function isApplicable(string $statement) : bool ;
  34. /**
  35. * Setup callback to current statement, can generate new statements.
  36. *
  37. * @param ElementHistory $elementHistory
  38. * @return callable
  39. */
  40. public function getCallback(ElementHistory $elementHistory) : callable;
  41. }