aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-03-16 16:17:12 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-03-22 16:22:01 -0700
commit6b7fdf3bf3675a14eae74acc5241089308153a34 (patch)
tree528a5a8c7022479561b67e33fd5cf14366d8c9d3 /activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
parentf20b2f4e54d27f7f98ca537ac69b1be8f88fc2a5 (diff)
downloadrails-6b7fdf3bf3675a14eae74acc5241089308153a34.tar.gz
rails-6b7fdf3bf3675a14eae74acc5241089308153a34.tar.bz2
rails-6b7fdf3bf3675a14eae74acc5241089308153a34.zip
add a pg visitor for dealing with schema modification
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb25
1 files changed, 21 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
index 3bc61c5e0c..766b5f07b1 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
@@ -1,6 +1,26 @@
module ActiveRecord
module ConnectionAdapters
class PostgreSQLAdapter < AbstractAdapter
+ class SchemaCreation < AbstractAdapter::SchemaCreation
+ private
+
+ def visit_AlterTable(o)
+ sql = "ALTER TABLE #{quote_table_name(o.name)} "
+
+ if col = o.add
+ sql_type = type_to_sql(col.type.to_sym, col.limit, col.precision, col.scale)
+ sql << "ADD COLUMN #{quote_column_name(col.name)} #{sql_type}"
+ add_column_options!(sql, column_options(col))
+ end
+
+ sql
+ end
+ end
+
+ def schema_creation
+ SchemaCreation.new self
+ end
+
module SchemaStatements
# Drops the database specified on the +name+ attribute
# and creates it again using the provided +options+.
@@ -337,10 +357,7 @@ module ActiveRecord
# See TableDefinition#column for details of the options you can use.
def add_column(table_name, column_name, type, options = {})
clear_cache!
- add_column_sql = "ALTER TABLE #{quote_table_name(table_name)} ADD COLUMN #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}"
- add_column_options!(add_column_sql, options)
-
- execute add_column_sql
+ super
end
# Changes the column of a table.