Skip to content

Commit 2e447b0

Browse files
committed
Support change_Table
1 parent ef99da0 commit 2e447b0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/activerecord-postgres-array/activerecord.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,24 @@ def quote_with_array(value, column = nil)
5050
alias_method_chain :quote, :array
5151
end
5252

53+
class Table
54+
# Adds array type for migrations. So you can add columns to a table like:
55+
# create_table :people do |t|
56+
# ...
57+
# t.string_array :real_energy
58+
# t.decimal_array :real_energy, :precision => 18, :scale => 6
59+
# ...
60+
# end
61+
PostgreSQLAdapter::POSTGRES_ARRAY_TYPES.each do |column_type|
62+
define_method("#{column_type}_array") do |*args|
63+
options = args.extract_options!
64+
base_type = @base.type_to_sql(column_type.to_sym, options[:limit], options[:precision], options[:scale])
65+
column_names = args
66+
column_names.each { |name| column(name, "#{base_type}[]", options) }
67+
end
68+
end
69+
end
70+
5371
class TableDefinition
5472
# Adds array type for migrations. So you can add columns to a table like:
5573
# create_table :people do |t|

0 commit comments

Comments
 (0)