Skip to content

Commit

Permalink
Add more default rules to MySQL datetime handling.
Browse files Browse the repository at this point in the history
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 dimitri#811.
  • Loading branch information
dimitri committed Jul 8, 2018
1 parent 1844823 commit 46d14af
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/sources/mysql/mysql-cast-rules.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions test/mysql/my.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 46d14af

Please sign in to comment.