Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.2 schema dump turns all UUID columns to text and mangles array declarations with postgres_ext gem

Using Ruby 2.0.0-p195 with Rails 3.2.13 and v0.3.1 of the postgres_ext gem.

It seems that I often have trouble with schema dumps (not SQL structure dumps) using Rails wherein the schema dumper converts UUID columns to text columns and arrays to text columns with defaults of "{}". Routine operations such as rake db:schema:dump cause destructive diffs like the following:

-    t.string   "dbas",         :default => [],                 :array => true
-    t.string   "industries",   :default => [],                 :array => true
+    t.text     "dbas",         :default => "{}"
+    t.text     "industries",   :default => "{}"
-    t.uuid     "uuid"
+    t.text     "uuid"

If I examine the structure of the DB manually or just ask Rails what type of column type it thinks a given attribute has, everything looks just fine.

Naturally, this problem wreaks all sorts of havoc. Short of switching to a SQL structure dump, how can I get proper schema dumps?

like image 604
yonkeltron Avatar asked Nov 13 '22 04:11

yonkeltron


1 Answers

With Rails 3.2, you'll need to use rake db:structure:dump to dump the SQL version of the schema instead of the Ruby version.

Rails 4 handles more types when using rake db:schema:dump, which is what you are looking for.

like image 106
phlipper Avatar answered Nov 14 '22 23:11

phlipper