From 46d14af0d38b26b066876ecf45a2569da31f1d7e Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Sun, 8 Jul 2018 20:34:55 +0200 Subject: [PATCH] Add more default rules to MySQL datetime handling. Given the variety of ways to setup default behavior for datetime and timestamp data types in MySQL, we need yet more default casting rules. It might be time to think about a more principled way to solve the problem, but on the other hand, this ad-hoc one also comes with full overriding flexibility for the end user. Fixes #811. --- src/sources/mysql/mysql-cast-rules.lisp | 8 ++++++++ test/mysql/my.sql | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/sources/mysql/mysql-cast-rules.lisp b/src/sources/mysql/mysql-cast-rules.lisp index e53daa3..f05ecde 100644 --- a/src/sources/mysql/mysql-cast-rules.lisp +++ b/src/sources/mysql/mysql-cast-rules.lisp @@ -119,6 +119,10 @@ :target (:type "timestamptz" :drop-default t :drop-not-null t) :using pgloader.transforms::zero-dates-to-null) + (:source (:type "datetime" :on-update-current-timestamp t :not-null nil) + :target (:type "timestamptz" :drop-default t) + :using pgloader.transforms::zero-dates-to-null) + (:source (:type "timestamp" :default "0000-00-00 00:00:00" :not-null t) :target (:type "timestamptz" :drop-default t :drop-not-null t) :using pgloader.transforms::zero-dates-to-null) @@ -131,6 +135,10 @@ :target (:type "timestamptz" :drop-default t :drop-not-null t) :using pgloader.transforms::zero-dates-to-null) + (:source (:type "timestamp" :on-update-current-timestamp t :not-null nil) + :target (:type "timestamptz" :drop-default t) + :using pgloader.transforms::zero-dates-to-null) + (:source (:type "date" :default "0000-00-00") :target (:type "date" :drop-default t) :using pgloader.transforms::zero-dates-to-null) diff --git a/test/mysql/my.sql b/test/mysql/my.sql index 17cd3b6..a9daefd 100644 --- a/test/mysql/my.sql +++ b/test/mysql/my.sql @@ -100,6 +100,24 @@ create table bits insert into bits(bool) values(0b00), (0b01); +/* + * https://github.com/dimitri/pgloader/issues/811 + */ +CREATE TABLE `domain_filter` ( + `id` binary(16) NOT NULL , + `type` varchar(50) NOT NULL , + `value` json DEFAULT NULL , + `negated` tinyint(1) NOT NULL DEFAULT '0' , + `report_id` varbinary(255) NOT NULL , + `query_id` varchar(255) NOT NULL , + `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP , + `updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP , + `updated_by` varbinary(255) DEFAULT NULL , + PRIMARY KEY (`id`), + UNIQUE KEY `domain_filter_unq` (`report_id`,`query_id`,`type`), + KEY `domain_filter` (`type`) +) ENGINE=InnoDB DEFAULT CHARSET=ascii; + /* * https://github.com/dimitri/pgloader/issues/703 */