From 2e447b03a27287f9f426ac922a70d7cd2c912895 Mon Sep 17 00:00:00 2001 From: Claudio Poli Date: Tue, 7 Aug 2012 11:44:57 +0200 Subject: [PATCH] Support change_Table --- .../activerecord.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/activerecord-postgres-array/activerecord.rb b/lib/activerecord-postgres-array/activerecord.rb index 7206464..e5558c5 100644 --- a/lib/activerecord-postgres-array/activerecord.rb +++ b/lib/activerecord-postgres-array/activerecord.rb @@ -50,6 +50,24 @@ def quote_with_array(value, column = nil) alias_method_chain :quote, :array end + class Table + # Adds array type for migrations. So you can add columns to a table like: + # create_table :people do |t| + # ... + # t.string_array :real_energy + # t.decimal_array :real_energy, :precision => 18, :scale => 6 + # ... + # end + PostgreSQLAdapter::POSTGRES_ARRAY_TYPES.each do |column_type| + define_method("#{column_type}_array") do |*args| + options = args.extract_options! + base_type = @base.type_to_sql(column_type.to_sym, options[:limit], options[:precision], options[:scale]) + column_names = args + column_names.each { |name| column(name, "#{base_type}[]", options) } + end + end + end + class TableDefinition # Adds array type for migrations. So you can add columns to a table like: # create_table :people do |t|