Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array-value default for Postgres UUID Array type fails in 5.1.2+ migrations #30539

Closed
booleanbetrayal opened this issue Sep 7, 2017 · 6 comments

Comments

@booleanbetrayal
Copy link

Steps to reproduce

(Guidelines for creating a bug report are available
here
)

Expected behavior

During a rails migration, the following schema change definition should continue to work 5.1.2+ with PostgreSQL 9.x:

add_column :some_table, :some_column, :uuid, array: true, default: []

Actual behavior

The statement fails with:

no implicit conversion of Array into String
activesupport-5.1.2/lib/active_support/core_ext/regexp.rb:7:in `match'
activesupport-5.1.2/lib/active_support/core_ext/regexp.rb:7:in `match?'
activerecord-5.1.2/lib/active_record/connection_adapters/postgresql/quoting.rb:65:in `quote_default_expression'
...

This worked previously in 5.1.1. A workaround is available using the PostgreSQL string array literal format:

add_column :some_table, :some_column, :uuid, array: true, default: '{}'

System configuration

Rails version:
5.1.2 / 5.1.3

Ruby version:
2.3.x

@booleanbetrayal booleanbetrayal changed the title Array-value default for Postgres UUID Array type fails in 5.1.2+ Array-value default for Postgres UUID Array type fails in 5.1.2+ Migrations Sep 7, 2017
@booleanbetrayal booleanbetrayal changed the title Array-value default for Postgres UUID Array type fails in 5.1.2+ Migrations Array-value default for Postgres UUID Array type fails in 5.1.2+ migrations Sep 7, 2017
@kamipo kamipo closed this as completed in a4b73f8 Sep 7, 2017
@booleanbetrayal
Copy link
Author

you're too fast @kamipo --- I was still finishing up the minitest for this. =]

@cdesch
Copy link

cdesch commented Jan 24, 2018

@booleanbetrayal How do you get this to work with Rails 5.1.4? I see @kamipo pull request to get it into Rails 5.2 ... which is awesome, but how do I handle this now?

@booleanbetrayal
Copy link
Author

@cdesch - if I recall, the Postgres literal worked for this: default: '{}'

@cdesch
Copy link

cdesch commented Jan 25, 2018

Thanks @booleanbetrayal - I'll give that a shot on my next try using the migrations. For the interim I just use SQL execute in the migration:

def up
  execute "ALTER TABLE requests ADD COLUMN examples uuid[] NOT null DEFAULT '{}'"
  execute "ALTER TABLE requests ADD COLUMN types uuid[] NOT null DEFAULT '{}'"
  execute "ALTER TABLE requests ADD COLUMN parts uuid[] NOT null DEFAULT '{}'"
end

@likeuwill
Copy link

That was implemented in 5.1.5 ;(

@cdesch
Copy link

cdesch commented Mar 8, 2018

Thanks @likeuwill! Can confirm it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants