1
0

TableMigrationAttribute.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\Migration\Attributes;
  8. use JsonSerializable;
  9. /**
  10. * generic class related to migration attribute about table changes
  11. *
  12. * @since 30.0.0
  13. */
  14. class TableMigrationAttribute extends MigrationAttribute implements JsonSerializable {
  15. /**
  16. * @param string $table name of the database table
  17. * @param array $columns list of columns
  18. * @param string $description description of the migration
  19. * @param array $notes notes about the migration/table
  20. * @since 30.0.0
  21. */
  22. public function __construct(
  23. string $table,
  24. private array $columns = [],
  25. string $description = '',
  26. array $notes = [],
  27. ) {
  28. parent::__construct($table, $description, $notes);
  29. }
  30. /**
  31. * @param array $columns
  32. *
  33. * @return $this
  34. * @since 30.0.0
  35. */
  36. public function setColumns(array $columns): self {
  37. $this->columns = $columns;
  38. return $this;
  39. }
  40. /**
  41. * @return array
  42. * @since 30.0.0
  43. */
  44. public function getColumns(): array {
  45. return $this->columns;
  46. }
  47. /**
  48. * @param array $data
  49. *
  50. * @return $this
  51. * @since 30.0.0
  52. */
  53. public function import(array $data): self {
  54. parent::import($data);
  55. $this->setColumns($data['columns'] ?? []);
  56. return $this;
  57. }
  58. /**
  59. * @return array
  60. * @since 30.0.0
  61. */
  62. public function jsonSerialize(): array {
  63. return array_merge(
  64. parent::jsonSerialize(),
  65. [
  66. 'columns' => $this->getColumns(),
  67. ]
  68. );
  69. }
  70. }