willbryant / kitchen_sync

Fast unidirectional synchronization - make or efficiently update a copy of a database, without slow dumping & reloading
MIT License
282 stars 35 forks source link

[question]. Can’t find an enumerated type with possible values #87

Closed martyzz1 closed 4 years ago

martyzz1 commented 4 years ago

I'm not entirely sure what this means, and what I need to do about it?

Kitchen Sync
Can’t find an enumerated type with possible values (‘always’, ‘no’, ‘on_no_only’, ‘on_yes_only’) for column inquire_details, please create one using CREATE TYPE
Kitchen Syncing failed.
martyzz1 commented 4 years ago

for context I'm trying to migrate a php laravel mysql database to a postgres DB

martyzz1 commented 4 years ago

ok seems I answered my own question and discovered more reasons to dislike mysql & laravel...

CREATE TYPE inquire_details AS ENUM ('always', 'no', 'on_no_only', 'on_yes_only');

This fixes the issue... But I'm still blocked where the same column name in mysql is used with an enum... Meaning I'd need to create an enum with the merged list..

martyzz1 commented 4 years ago

hmm that doesn't work

CREATE TYPE status AS ENUM ('ACTIVE', 'INACTIVE');
CREATE TYPE status AS ENUM ('PUBLISHED', 'DRAFT', 'PENDING');

ERROR: type "status" already exists

DROP TYPE status;
CREATE TYPE status AS ENUM ('PUBLISHED', 'DRAFT', 'PENDING', 'ACTIVE', 'INACTIVE');

Still results in Can't find an enumerated type with possible values ('ACTIVE', 'INACTIVE') for column status, please create one using CREATE TYPE

martyzz1 commented 4 years ago

assuming only option is to rename the column of one of those "status" fields in the mysql

martyzz1 commented 4 years ago

alter table posts CHANGE status ENUM varchar(12);

seems to have worked

willbryant commented 4 years ago

Cool. Just to clarify, the ENUM doesn't have to have the same name as the column. Since MySQL doesn't define or name its enumeration types, when syncing from mysql to postgresql Kitchen Sync just tries to find any enumeration with the right values in postgresql's type system.

So you can pick a naming scheme for the postgresql enumerations like table1_status_t and table2_status_t or table1_status_enum_type and table2_status_enum_type or something, to avoid any naming conflicts with the columns or between the two status types.