diff --git a/resources/sql/patches/liskcounters-task.sql b/resources/sql/patches/liskcounters-task.sql new file mode 100644 index 0000000000..c75a7f1cdf --- /dev/null +++ b/resources/sql/patches/liskcounters-task.sql @@ -0,0 +1,8 @@ +ALTER TABLE `{$NAMESPACE}_worker`.worker_task + CHANGE id id INT UNSIGNED NOT NULL; + +RENAME TABLE `{$NAMESPACE}_worker`.worker_task + TO `{$NAMESPACE}_worker`.worker_activetask; + +UPDATE `{$NAMESPACE}_worker`.lisk_counter + SET counterName = 'worker_activetask' WHERE counterName = 'worker_task'; diff --git a/resources/sql/patches/liskcounters.php b/resources/sql/patches/liskcounters.php index 6166640c24..489747575f 100644 --- a/resources/sql/patches/liskcounters.php +++ b/resources/sql/patches/liskcounters.php @@ -6,6 +6,8 @@ $active_table = new PhabricatorWorkerActiveTask(); $archive_table = new PhabricatorWorkerArchiveTask(); +$old_table = 'worker_task'; + $conn_w = $active_table->establishConnection('w'); $active_auto = head(queryfx_one( @@ -13,12 +15,12 @@ $active_auto = head(queryfx_one( 'SELECT auto_increment FROM information_schema.tables WHERE table_name = %s AND table_schema = DATABASE()', - $active_table->getTableName())); + $old_table)); $active_max = head(queryfx_one( $conn_w, 'SELECT MAX(id) FROM %T', - $active_table->getTableName())); + $old_table)); $archive_max = head(queryfx_one( $conn_w, @@ -33,12 +35,6 @@ queryfx( VALUES (%s, %d) ON DUPLICATE KEY UPDATE counterValue = %d', LiskDAO::COUNTER_TABLE_NAME, - $active_table->getTableName(), + $old_table, $initial_counter + 1, $initial_counter + 1); - -// Drop AUTO_INCREMENT from the ID column. -queryfx( - $conn_w, - 'ALTER TABLE %T CHANGE id id INT UNSIGNED NOT NULL', - $active_table->getTableName()); diff --git a/src/infrastructure/daemon/workers/storage/PhabricatorWorkerActiveTask.php b/src/infrastructure/daemon/workers/storage/PhabricatorWorkerActiveTask.php index 37c750f9e8..cb1fd41acc 100644 --- a/src/infrastructure/daemon/workers/storage/PhabricatorWorkerActiveTask.php +++ b/src/infrastructure/daemon/workers/storage/PhabricatorWorkerActiveTask.php @@ -5,10 +5,6 @@ final class PhabricatorWorkerActiveTask extends PhabricatorWorkerTask { private $serverTime; private $localTime; - public function getTableName() { - return 'worker_task'; - } - public function getConfiguration() { return array( self::CONFIG_IDS => self::IDS_COUNTER, @@ -71,7 +67,7 @@ final class PhabricatorWorkerActiveTask extends PhabricatorWorkerTask { } public function archiveTask($result, $duration) { - if (!$this->getID()) { + if ($this->getID() === null) { throw new Exception( "Attempting to archive a task which hasn't been save()d!"); } diff --git a/src/infrastructure/daemon/workers/storage/PhabricatorWorkerArchiveTask.php b/src/infrastructure/daemon/workers/storage/PhabricatorWorkerArchiveTask.php index 6bf24ed450..6cdfa93922 100644 --- a/src/infrastructure/daemon/workers/storage/PhabricatorWorkerArchiveTask.php +++ b/src/infrastructure/daemon/workers/storage/PhabricatorWorkerArchiveTask.php @@ -10,7 +10,7 @@ final class PhabricatorWorkerArchiveTask extends PhabricatorWorkerTask { protected $result; public function save() { - if (!$this->getID()) { + if ($this->getID() === null) { throw new Exception( "Trying to archive a task with no ID."); } diff --git a/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php b/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php index c7a267f48d..78f3fd8ac1 100644 --- a/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php +++ b/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php @@ -1028,6 +1028,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList { 'type' => 'sql', 'name' => $this->getPatchPath('repository-lint.sql'), ), + 'liskcounters-task.sql' => array( + 'type' => 'sql', + 'name' => $this->getPatchPath('liskcounters-task.sql'), + ), ); }