preaction / Minion-Backend-mysql

MySQL backend for the 🐙 Minion job runner
Other
7 stars 14 forks source link

Issue with multiple columns having default CURRENT_TIMESTAMP #24

Open crlcu opened 4 years ago

crlcu commented 4 years ago
DBD::mysql::st execute failed: Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause at <filename>
preaction commented 4 years ago

What version of MySQL are you running? Versions before 5.6.5 do not allow more than one timestamp column with a DEFAULT CURRENT_TIMESTAMP or ON UPDATE CURRENT_TIMESTAMP clauses (see the release notes for MySQL 5.6.5).

If you'd like, you can try this patch. If it works, I can apply it and add support for your version of MySQL.

diff --git a/lib/Minion/Backend/mysql.pm b/lib/Minion/Backend/mysql.pm
index c9020c2..dd67734 100644
--- a/lib/Minion/Backend/mysql.pm
+++ b/lib/Minion/Backend/mysql.pm
@@ -319,8 +319,8 @@ sub register_worker {
   my ($self, $id, $options) = @_;

   my $db = $self->mysql->db;
-  my $sql = q{INSERT INTO minion_workers (id, host, pid, status)
-    VALUES (?, ?, ?, ?)
+  my $sql = q{INSERT INTO minion_workers (id, host, pid, status, started, notified)
+    VALUES (?, ?, ?, ?, NOW(), NOW())
     ON DUPLICATE KEY UPDATE notified=NOW(), host=VALUES(host), pid=VALUES(pid), status=VALUES(status)};
   $db->query($sql, $id, hostname, $$, encode_json( $options->{status} // {} ) );

@@ -1002,7 +1002,7 @@ create table if not exists minion_jobs (
                `id`       serial not null primary key,
                `args`     mediumblob not null,
                `created`  timestamp not null default current_timestamp,
-               `delayed`  timestamp not null default current_timestamp,
+               `delayed`  timestamp not null,
                `finished` timestamp null,
                `priority` int not null,
                `result`   mediumblob,
@@ -1019,7 +1019,7 @@ create table if not exists minion_workers (
                `host`    text not null,
                `pid`     int not null,
                `started` timestamp not null default current_timestamp,
-               `notified` timestamp not null default current_timestamp
+               `notified` timestamp not null
 );

 -- 1 down
@@ -1034,7 +1034,7 @@ alter table minion_jobs add queue varchar(128) not null default 'default';

 -- 4 up
 ALTER TABLE minion_workers MODIFY COLUMN started timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP;
-ALTER TABLE minion_workers MODIFY COLUMN notified timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP;
+ALTER TABLE minion_workers MODIFY COLUMN notified timestamp NOT NULL;
 CREATE TABLE IF NOT EXISTS minion_workers_inbox (
   `id` SERIAL NOT NULL PRIMARY KEY,
   `worker_id` BIGINT UNSIGNED NOT NULL,