20220909202811_merge_node_info.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. declare(strict_types=1);
  3. use Phinx\Migration\AbstractMigration;
  4. final class MergeNodeInfo extends AbstractMigration
  5. {
  6. public function up(): void
  7. {
  8. if (! $this->table('node')->hasColumn('load')) {
  9. $this->table('node')
  10. ->addColumn('load', 'string', ['default' => ''])
  11. ->save();
  12. }
  13. if (! $this->table('node')->hasColumn('uptime')) {
  14. $this->table('node')
  15. ->addColumn('uptime', 'integer', ['default' => 0])
  16. ->save();
  17. }
  18. if ($this->hasTable('node_info')) {
  19. $this->table('node_info')->drop()->update();
  20. }
  21. }
  22. public function down(): void
  23. {
  24. $this->table('node')
  25. ->removeColumn('load')
  26. ->removeColumn('uptime')
  27. ->save();
  28. $this->table('node_info', [ 'id' => false, 'primary_key' => [ 'id' ]])
  29. ->addColumn('id', 'biginteger', [ 'identity' => true,'signed' => false ])
  30. ->addColumn('node_id', 'integer', [])
  31. ->addColumn('uptime', 'float', [])
  32. ->addColumn('load', 'string', [])
  33. ->addColumn('log_time', 'integer', [])
  34. ->addIndex([ 'node_id' ])
  35. ->addForeignKey('node_id', 'node', 'id', [ 'delete' => 'CASCADE', 'update' => 'CASCADE' ])
  36. ->create();
  37. }
  38. }