invalid schema created when adding array column with default empty array #504

Closed
nurey opened this Issue Nov 25, 2013 · 1 comment

Projects

None yet

2 participants

@nurey

activerecord-jdbc-adapter 1.3.2 (also master)
jruby 1.7.8 (1.9.3p392) 2013-11-14 0ce429e on Java HotSpot(TM) 64-Bit Server VM 1.7.0_40-b43 [darwin-x86_64]

If I use this migration:
add_column :table_name, :path, :integer, array: true, default: []

I get a schema.rb that looks like this:

create_table "table_name" do |t|
    ...
    t.integer  "path",                    default: "{}",              array: true
end

Running rake db:schema:load on such a schema results in:

ActiveRecord::JDBCError: org.postgresql.util.PSQLException: ERROR: column "path" is of type integer[] but default expression is of type integer
  Hint: You will need to rewrite or cast the expression.: CREATE TABLE "social_messages" ("id" serial primary key, "type" character varying(255), "origin_id_str" character varying(255), "created_at" timestamp, "updated_at" timestamp, "author_id" integer, "parent_id" bigint, "message" text, "metadata" hstore, "sentiment" character varying(255), "intent" character varying(255), "posted_at" timestamp, "replies_count" integer DEFAULT 0 NOT NULL, "path" integer[] DEFAULT 0) 
arjdbc/jdbc/RubyJdbcConnection.java:537:in `execute'
/tmp/runner/gitlab-ci-runner-3/tmp/builds/project-1/vendor/bundle/jruby/1.9/gems/activerecord-jdbc-adapter-1.3.2/lib/arjdbc/jdbc/adapter.rb:571:in `_execute'
/tmp/runner/gitlab-ci-runner-3/tmp/builds/project-1/vendor/bundle/jruby/1.9/gems/activerecord-jdbc-adapter-1.3.2/lib/arjdbc/jdbc/adapter.rb:547:in `execute'

the schema should be generated with default looking like this:
t.integer "path", default: [], array: true

@kares
JRuby Team member

should be fine now due a2cbc1f thx!

@kares kares closed this Dec 7, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment