long2ice / meilisync

Realtime sync data from MySQL/PostgreSQL/MongoDB to Meilisearch
https://github.com/long2ice/meilisync
Apache License 2.0
250 stars 37 forks source link

Unable to insert date fields from mysql source #8

Closed brunoocasali closed 1 year ago

brunoocasali commented 1 year ago

Hi @long2ice, first of all, thanks a lot for this tool. It will be incredibly helpful for everyone. Congratulations on your work!

Before officially starting sharing this tool, I want to ensure everything is working fine, so I'll raise some issues where we can work together to improve it!

So, my table is quite simple:

mysql> SHOW FULL FIELDS FROM authors;
+------------+--------------+--------------------+------+-----+-------------------+-------------------+---------------------------------+---------+
| Field      | Type         | Collation          | Null | Key | Default           | Extra             | Privileges                      | Comment |
+------------+--------------+--------------------+------+-----+-------------------+-------------------+---------------------------------+---------+
| id         | int          | NULL               | NO   | PRI | NULL              | auto_increment    | select,insert,update,references |         |
| first_name | varchar(50)  | utf8mb3_unicode_ci | NO   |     | NULL              |                   | select,insert,update,references |         |
| last_name  | varchar(50)  | utf8mb3_unicode_ci | NO   |     | NULL              |                   | select,insert,update,references |         |
| email      | varchar(100) | utf8mb3_unicode_ci | NO   | UNI | NULL              |                   | select,insert,update,references |         |
| birthdate  | date         | NULL               | NO   |     | NULL              |                   | select,insert,update,references |         |
| added      | timestamp    | NULL               | NO   |     | CURRENT_TIMESTAMP | DEFAULT_GENERATED | select,insert,update,references |         |
+------------+--------------+--------------------+------+-----+-------------------+-------------------+---------------------------------+---------+

fake data example:

INSERT INTO `authors` (`id`, `first_name`, `last_name`, `email`, `birthdate`, `added`) VALUES (1, 'Flo', 'Hansen', 'raynor.anika@example.com', '2012-06-07', '1977-01-27 22:00:53');
meilisync-meilisync-1    | TypeError: Object of type date is not JSON serializable
meilisync-meilisync-1    | 2023-04-21 15:32:23.624 | ERROR    | meilisync.main:interval:122 - Error when insert data to MeiliSearch: Object of type date is not JSON serializable

I'm running this MySQL version: 8.0.33 for Linux on aarch64 (MySQL Community Server - GPL). And the import was not completed. Since there is no way to inform in the configuration file which types the column has, the system should automatically understand it, right?

brunoocasali commented 1 year ago

By the way, I had some weird issues regarding my collation. So I set everything, even the database, to utf8mb4_unicode_ci and it worked fine. I didn't know if it was something caused by my poor-configurated test database.

long2ice commented 1 year ago

Yes, maybe we should convert datetime to str before insert into meilisearch