greenhost/BackJob

start_time

Closed this issue · 2 comments

When BackJob do the createTable

    /**
     * Create the table used for storing jobs DB-side.
     */
    private function createTable() {
        $this->database->createCommand(
            $this->database->schema->createTable(
                $this->tableName, array(
                    'id' => 'pk',
                    'progress' => 'integer',
                    'status' => 'integer',
                    'start_time' => 'timestamp',
                    'updated_time' => 'timestamp',
                    'end_time' => 'timestamp',
                    'request' => 'text',
                    'status_text' => 'text',
                )
            )
        )->execute();
    }

Yii creates the table this way:

CREATE TABLE `e_background_job` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `progress` int(11) DEFAULT NULL,
  `status` int(11) DEFAULT NULL,
  `start_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `end_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `request` text,
  `status_text` text,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

The problem is the default value for start_time, because every time you update, start_time updates to CURRENT_TIMESTAMP, and the real start time get lost.

It can be solved like this:

    /**
     * Create the table used for storing jobs DB-side.
     */
    private function createTable() {
        $this->database->createCommand(
            $this->database->schema->createTable(
                $this->tableName, array(
                    'id' => 'pk',
                    'progress' => 'integer',
                    'status' => 'integer',
                    'start_time' => 'timestamp NOT NULL DEFAULT \'0000-00-00 00:00:00\'',
                    'updated_time' => 'timestamp',
                    'end_time' => 'timestamp',
                    'request' => 'text',
                    'status_text' => 'text',
                )
            )
        )->execute();
    }

You're right, no idea why yii decided to add that "on update"... specifying the default as current timestamp works, fixed in next version