This project is archived and is in readonly mode.
SQLite / SQLite3 ActiveRecord Adapter should quote table names when renaming tables
Reported by Denis Defreyne | March 17th, 2009 @ 03:26 PM | in 2.x
OVERVIEW
ActiveRecord does not always quote table names when using SQLite3, which may cause migrations to break when using keywords as table names.
STEPS TO REPRODUCE
- Create a new rails project.
- Create the CreateReferences migration (see below).
- Run the db:migrate task.
- Create the RenameReferencesToItems migration (see below).
- Run the db:migrate task.
The CreateReferences migration:
create_table :references, :force => true do |t|
t.string :foo
t.string :bar
t.timestamps
end
The RenameReferencesToItems:
rename_table :references, :items
ACTUAL RESULTS
Step 3 runs correctly. The "references" table is created.
Step 5 fails to run correctly. This is the output of the rake task:
== RenameReferencesToItems: migrating =====
-- rename_table(:references, :items)
rake aborted!
An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: near "references": syntax error: ALTER TABLE references RENAME TO items
EXPECTED RESULTS
Step 5 should not fail. It should rename the "references" table to "items". The generated SQL should be
ALTER TABLE "references" RENAME TO items
instead of
ALTER TABLE references RENAME TO items
AFFECTED VERSIONS
- SQLite3: 3.6.11.
- ActiveRecord: 2.3.2
- Ruby: 1.8.7
Comments and changes to this ticket
-
Brian Hogan March 20th, 2009 @ 03:00 AM
- Tag set to 2.3.2, activerecord, patch, sql, sqlite, sqlite3
Here's a patch with tests that resolves the issue. I've seen this come up for quite some time now and finally figured out how to write appropriate tests. Anyone wanna review this and apply it? :)
-
Brian Hogan March 20th, 2009 @ 03:15 AM
How about we try this again with a patch that uses the quote_table_name mechanism instead of just single quotes? :)
-
Brian Hogan March 20th, 2009 @ 01:47 PM
- Title changed from ActiveRecord should quote table names to SQLite / SQLite3 ActiveRecord Adapter should quote table names when renaming tables
Changed title to make this more descriptive
-
Brian Hogan March 22nd, 2009 @ 05:20 AM
Thanks to tpope for noticing my tests sucked - Patch with better tests.
-
Pratik June 21st, 2009 @ 06:26 PM
- State changed from new to resolved
Resolved in b26c2c11ab47dbd4d1e26806d1e861edc7d697e0
-
Repository June 21st, 2009 @ 09:27 PM
(from [b26c2c11ab47dbd4d1e26806d1e861edc7d697e0]) Ensure table names are quoted while renaming for sqlite3 adapter [#2272 state:resolved]
Signed-off-by: Pratik Naik pratiknaik@gmail.com
http://github.com/rails/rails/commit/b26c2c11ab47dbd4d1e26806d1e861... -
Repository June 23rd, 2009 @ 10:50 PM
(from [6d74e9d0b431e2487b498e4532bb1d8edcafa855]) Ensure table names are quoted while renaming for sqlite3 adapter [#2272 state:resolved]
Signed-off-by: Pratik Naik pratiknaik@gmail.com
http://github.com/rails/rails/commit/6d74e9d0b431e2487b498e4532bb1d...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 2272 SQLite / SQLite3 ActiveRecord Adapter should quote table names when renaming tables (from [b26c2c11ab47dbd4d1e26806d1e861edc7d697e0]) Ensure ...
- 2272 SQLite / SQLite3 ActiveRecord Adapter should quote table names when renaming tables (from [6d74e9d0b431e2487b498e4532bb1d8edcafa855]) Ensure ...