Skip to content
Browse files

clear statement cache when tables are altered

  • Loading branch information...
1 parent 9317752 commit 74fbbca2f8007413e121859b85a18244d6a1cf09 @tenderlove tenderlove committed
Showing with 6 additions and 0 deletions.
  1. +6 −0 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
View
6 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -910,12 +910,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)
@@ -924,6 +926,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])}"
@@ -934,10 +937,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
@@ -946,6 +951,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

0 comments on commit 74fbbca

Please sign in to comment.
Something went wrong with that request. Please try again.