Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10855: drop_table_if_exists_with_test.diff

File drop_table_if_exists_with_test.diff, 1.7 kB (added by kampers, 5 months ago)
  • activerecord/test/cases/migration_test.rb

    old new  
    181181      Person.connection.drop_table :testings rescue nil 
    182182    end 
    183183 
     184    # PostgreSQL returns an error when dropping a table that doesn't exist, 
     185    # unless you use <tt>IF EXISTS</tt>. <tt>:force => true</tt> uses this syntax. 
     186    if current_adapter?(:PostgreSQLAdapter) 
     187      def test_drop_table_force 
     188        assert_nothing_raised do 
     189          Person.connection.drop_table :does_not_exist, :force => true 
     190        end 
     191      end 
     192    end 
     193 
    184194    # SQL Server, Sybase, and SQLite3 will not allow you to add a NOT NULL 
    185195    # column to a table without a default value. 
    186196    unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :SQLiteAdapter) 
  • activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb

    old new  
    587587        execute "ALTER TABLE #{name} RENAME TO #{new_name}" 
    588588      end 
    589589 
     590      # Drops a table from the database. 
     591      def drop_table(table_name, options = {}) 
     592        args = options[:force] ? " IF EXISTS" : "" 
     593        execute "DROP TABLE#{args} #{quote_table_name(table_name)}" 
     594      end 
     595 
    590596      # Adds a new column to the named table. 
    591597      # See TableDefinition#column for details of the options you can use. 
    592598      def add_column(table_name, column_name, type, options = {})