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.
This commit is contained in:
Dimitri Fontaine 2018-07-08 20:34:55 +02:00
parent 1844823bce
commit 46d14af0d3
2 changed files with 26 additions and 0 deletions

View File

@ -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)

18
test/mysql/my.sql vendored
View File

@ -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
*/