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

fix for #10613 . This PR is still WIP. #12519

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,14 @@ def type_cast(value)

class Array < Type
attr_reader :subtype
attr_writer :typecast
def initialize(subtype)
@subtype = subtype
@typecast = true
end

def type_cast(value)
return value unless @typecast
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this guard?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rafaelfranca I'm not able to recall why I added that. :-(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😢

if String === value
ConnectionAdapters::PostgreSQLColumn.string_to_array value, @subtype
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,15 @@ def indexes(table_name, name = nil)
end

# Returns the list of all column definitions for a table.
def columns(table_name)
def columns(table_name, typecast = true)
# Limit, precision, and scale are all handled by the superclass.
column_definitions(table_name).map do |column_name, type, default, notnull, oid, fmod|
oid = OID::TYPE_MAP.fetch(oid.to_i, fmod.to_i) {
OID::Identity.new
}
if !typecast && ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::Array === oid && ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::Identity === oid.subtype
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of type checking we should define an API with a default implementation and implement it in a different way on Array

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rafaelfranca will look into it this week.

oid.typecast = false
end
PostgreSQLColumn.new(column_name, default, oid, type, notnull == 'f')
end
end
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/schema_dumper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def tables(stream)
end

def table(table, stream)
columns = @connection.columns(table)
columns = @connection.columns(table, false)
begin
tbl = StringIO.new

Expand Down