Permalink
Browse files

clear statement cache when tables are altered

  • Loading branch information...
1 parent 420f7fd commit 4a065d56edcafacc99196522ea35fe28c5f45937 @tenderlove tenderlove committed Oct 27, 2011
Showing with 6 additions and 0 deletions.
  1. +6 −0 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -922,12 +922,14 @@ def primary_key(table)
# Example:
# rename_table('octopuses', 'octopi')
def rename_table(name, new_name)
+ clear_cache!
execute "ALTER TABLE #{quote_table_name(name)} RENAME TO #{quote_table_name(new_name)}"
end
# Adds a new column to the named table.
# 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)
@@ -936,6 +938,7 @@ def add_column(table_name, column_name, type, options = {})
# Changes the column of a table.
def change_column(table_name, column_name, type, options = {})
+ clear_cache!
quoted_table_name = quote_table_name(table_name)
execute "ALTER TABLE #{quoted_table_name} ALTER COLUMN #{quote_column_name(column_name)} TYPE #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}"
@@ -946,10 +949,12 @@ def change_column(table_name, column_name, type, options = {})
# Changes the default value of a table column.
def change_column_default(table_name, column_name, default)
+ clear_cache!
execute "ALTER TABLE #{quote_table_name(table_name)} ALTER COLUMN #{quote_column_name(column_name)} SET DEFAULT #{quote(default)}"
end
def change_column_null(table_name, column_name, null, default = nil)
+ clear_cache!
unless null || default.nil?
execute("UPDATE #{quote_table_name(table_name)} SET #{quote_column_name(column_name)}=#{quote(default)} WHERE #{quote_column_name(column_name)} IS NULL")
end
@@ -958,6 +963,7 @@ def change_column_null(table_name, column_name, null, default = nil)
# Renames a column in a table.
def rename_column(table_name, column_name, new_column_name)
+ clear_cache!
execute "ALTER TABLE #{quote_table_name(table_name)} RENAME COLUMN #{quote_column_name(column_name)} TO #{quote_column_name(new_column_name)}"
end

1 comment on commit 4a065d5

Contributor

sobrinho commented on 4a065d5 Oct 28, 2011

Missing tests :/

The previous commit only coverage change_column

Please sign in to comment.