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

Default values can't be loaded from schema.rb #39

Open
emma-borhanian opened this issue Aug 29, 2014 · 0 comments
Open

Default values can't be loaded from schema.rb #39

emma-borhanian opened this issue Aug 29, 2014 · 0 comments

Comments

@emma-borhanian
Copy link

For an empty array, the default ends up looking like :default => '{}' in schema.rb, however, this doesn't get single-quoted when turned into a CREATE TABLE statement, causing rake db:schema:load to fail.

The following patch fixes it for string arrays, by causing it to be encoded in schema.rb as :default => [] and could probably be generalized:

require 'active_record/connection_adapters/postgresql_adapter'
module ConnectionAdapters
  class PostgreSQLColumn < Column
    class << self
      def extract_value_from_default_with_array(default)
        case default
        when NilClass
          nil
        # Arrays
        when /\A'(.*)'::"?character varying.*"?\[\]\z/
          $1.from_postgres_array(:string)
        else
          extract_value_from_default_without_array(default)
        end
      end
      alias_method_chain :extract_value_from_default, :array
    end
  end
end
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

1 participant