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

Ticket #9344 (closed enhancement: fixed)

Opened 9 months ago

Last modified 6 days ago

[PATCH] Refactor table_exists? to adapters

Reported by: tarmo Assigned to: core
Priority: normal Milestone: 2.x
Component: ActiveRecord Version: edge
Severity: normal Keywords:
Cc:

Description

ActiveRecord::Base has a "table_exists?" method which currently assumes that not all the connection adapters can provide the list of tables. Since all adapters do have the "tables" method for getting a list of tables there appears to be no good reason to make such assumptions which only make the code more complex.

Additionally, since "table_exists?" is only defined in AR::Base it can not be used for other purposes, for example in migrations.

For those reasons I've added "table_exits?(table_name)" method to abstract adapter, implemented in the simple way that assumes that the adapter does support getting a list of all tables.

I refactored the method in AR::Base to use the one added to the adapters.

And in addition to that I changed "create_table :force => true" to actually check if the table exists and not ignore errors when dropping the table fails (in a way this fixes #5818, though it does not fix all the errors, at least it allows the user to see that dropping the table failed and why it failed).

Attachments

refactor_table_exists_to_adapters.patch (10.9 kB) - added by tarmo on 08/22/07 23:02:32.

Change History

08/22/07 23:02:32 changed by tarmo

  • attachment refactor_table_exists_to_adapters.patch added.

08/22/07 23:03:58 changed by tarmo

Tests pass on postgresql 8.2, mysql 5.0, sqlite 2.8, sqlite 3.4. The patch appears long but a lot of it is indentation changes.

08/27/07 17:27:47 changed by lifofifo

+1

05/07/08 12:57:06 changed by tarmo

  • status changed from new to closed.
  • resolution set to fixed.