dimitri / pgloader

Migrate to PostgreSQL in a single command!

Home Page:http://pgloader.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mysql8.0, miss on-update-current-timestamp trigger when the column has default value

optionals opened this issue · comments

commented

mysql

CREATE TABLE `onupdate` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `patient_id` varchar(50) NOT NULL,
  `update_date1` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `update_date2` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE current_timestamp(),
  `update_date3` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp(),
  `update_date4` timestamp NULL ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `patient_id` (`patient_id`)
);

then show COLUMNS

SHOW COLUMNS FROM onupdate; 
+--------------+-------------+------+-----+-------------------+-----------------------------------------------+
| Field        | Type        | Null | Key | Default           | Extra                                         |
+--------------+-------------+------+-----+-------------------+-----------------------------------------------+
| id           | int         | NO   | PRI | NULL              | auto_increment                                |
| patient_id   | varchar(50) | NO   | UNI | NULL              |                                               |
| update_date1 | timestamp   | NO   |     | CURRENT_TIMESTAMP | DEFAULT_GENERATED on update CURRENT_TIMESTAMP |
| update_date2 | timestamp   | NO   |     | CURRENT_TIMESTAMP | DEFAULT_GENERATED on update CURRENT_TIMESTAMP |
| update_date3 | timestamp   | YES  |     | NULL              | on update CURRENT_TIMESTAMP                   |
| update_date4 | timestamp   | YES  |     | NULL              | on update CURRENT_TIMESTAMP                   |
+--------------+-------------+------+-----+-------------------+-----------------------------------------------+

pg

loader@/tmp:loader> \df
+--------+--------------------------------------+------------------+---------------------+---------+
| Schema | Name                                 | Result data type | Argument data types | Type    |
|--------+--------------------------------------+------------------+---------------------+---------|
| loader | on_update_current_timestamp_onupdate | trigger          |                     | trigger |
+--------+--------------------------------------+------------------+---------------------+---------+
SELECT 1
Time: 0.092s

Extra

Any additional information that is available about a given column. The value is nonempty in these cases:

  • auto_increment for columns that have the AUTO_INCREMENT attribute.

  • on update CURRENT_TIMESTAMP for TIMESTAMP or DATETIME columns that have the ON UPDATE CURRENT_TIMESTAMP attribute.

  • VIRTUAL GENERATED or STORED GENERATED for generated columns.

  • DEFAULT_GENERATED for columns that have an expression default value.

fix

I add a judgmental condition as a temporary solution

;;; src/sources/mysql/mysql-cast-rules.lisp
(defun normalize-extra (extra)
  "Normalize MySQL strings into pgloader CL keywords for internal processing."
  (cond ((string= "auto_increment" extra)
         :auto-increment)

        ((or (string= extra "on update CURRENT_TIMESTAMP")
             (string= extra "on update current_timestamp()")
             (string= extra "DEFAULT_GENERATED on update CURRENT_TIMESTAMP"))
         :on-update-current-timestamp)))