the4thdoctor / pg_chameleon

MySQL to PostgreSQL replica system
http://www.pgchameleon.org
BSD 2-Clause "Simplified" License
378 stars 83 forks source link

DEFAULT values are not migrated. #78

Open Sahaquielxo opened 6 years ago

Sahaquielxo commented 6 years ago

Hi, once more issue. MySQL table:

| CREATE TABLE `rates_v2` (
  `host` varchar(20) NOT NULL,
  `rate` varchar(20) NOT NULL DEFAULT '',
  `added` datetime DEFAULT NULL,
  `new` set('N','Y') DEFAULT 'Y',
  `longweek` datetime DEFAULT NULL,
  `longmonth` datetime DEFAULT NULL,
  `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `hostId` tinyint(3) unsigned NOT NULL DEFAULT '1',
  `foreign_key` set('N','Y') DEFAULT 'Y',
  PRIMARY KEY (`host`,`hostId`,`rate`),
  KEY `Host` (`hostId`),
  KEY `rateTableNameIndex` (`new`,`rate`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
r=> \d+ rates_v2;
                                             Table "rates_v2"
   Column    |            Type             | Collation | Nullable | Default | Storage  | Stats target | Description
-------------+-----------------------------+-----------+----------+---------+----------+--------------+-------------
 host        | character varying(20)       |           | not null |         | extended |              |
 rate        | character varying(20)       |           | not null |         | extended |              |
 added       | timestamp without time zone |           |          |         | plain    |              |
 new         | text                        |           |          |         | extended |              |
 longweek    | timestamp without time zone |           |          |         | plain    |              |
 longmonth   | timestamp without time zone |           |          |         | plain    |              |
 updated     | timestamp without time zone |           | not null |         | plain    |              |
 hostId      | integer                     |           | not null |         | plain    |              |
 foreign_key | text                        |           |          |         | extended |              |

As you can see, for the row updated, DEFAULT value CURRENT_TIMESTAMP from MySQL did not migrated into PostgreSQL.

If chameleon is able to resolve this issue right now, or I have to wait for new release? Thanks for answer.

the4thdoctor commented 6 years ago

hi, I'm fairly sure I decided to not set the default values on purpose and trust the data coming from the mysql replica. I can check if this can cause problems and eventually fix the issue.

Many thanks for the report.

the4thdoctor commented 6 years ago

I've tested the functionality and the default values are correctly determined by mysql. However I'll think a way to add the default values on the postgres tables (thinking of a migration scenario).

Regarding the ticket #74 I can't add the functionality until the replication library returns the data as string '0000-00-00 00:00:00'. I've added a reference to a PR I'm waiting to be merged.

Thanks

grepsedawk commented 3 years ago

As far as I can tell, default values are still not transferred to psql For our migration, I think I'll write a bulk default migration within my rails app

timkrins commented 2 years ago

I also came across this today while using a replicated database after running chameleon detach_replica. It seems everything comes across absolutely fine - all except the default values.

bomuva commented 1 year ago

Definition of default value for table column still not replicated