stripe-archive / mosql

MongoDB → PostgreSQL streaming replication
MIT License
1.62k stars 224 forks source link

Covert arrays to to postgres style arrays #46

Closed edkurowski closed 10 years ago

edkurowski commented 10 years ago

Currently, arrays are transformed into a string with the following format: '[elem1, elem2]'.

Unfortunately, Postgres wants you to use curly braces for arrays (for example, '{elem1, elem2}') and the current implementation throws an error when trying to execute an insert/update on columns with an array type.

This change uses a helper method from Sequel to convert an array to a Postgres compatible array.

Postgres Arrays docs: http://www.postgresql.org/docs/9.3/static/arrays.html

Sequel pg_array docs: http://sequel.jeremyevans.net/rdoc-plugins/files/lib/sequel/extensions/pg_array_rb.html

shaneog commented 10 years ago

:+1:

nelhage commented 10 years ago

Will this properly create the schema as an array type? I'd love to take a patch to do this, but I think we'll need some way to denote in the collection map that the column should be an array type, so that we can create the right schema. That'd also let us preserve compatibility with existing installations, by defaulting to JSON unless the schema calls out an array type.

I'd also like to see some tests.

edkurowski commented 10 years ago

This does create the proper array type in postgres and will insert the data correctly. I'll update the logic so that it will only treat the value as an array type if the schema has been set up to match. And of course, I will have some tests for you. Thanks.

nelhage commented 10 years ago

Thanks! Added a few small fixes on top, and merged.