Sqlite3 migration and CURRENT_TIMESTAMP


#1

I’m trying out migrations for the first time, and I’m having a problem
with my sqlite3 db. A trivial example of what I’m seeing:

class InitDb < ActiveRecord::Migration
def self.up
create_table :mytable, :force => true do |t|
t.column :lname, :string
t.column :created_at, :string, :default =>
‘CURRENT_TIMESTAMP’
end
end
def self.down
end
end

When I dump the SQL from that command (with #to_sql), the
CURRENT_TIMESTAMP field is single quoted. This tells Sqlite3 that you
want to use a string literal as the default, not the CURRENT_TIMESTAMP
function. So, instead of default timestamps, I get literal
“CURRENT_TIMESTAMP” strings in my records.

Is there any way to tell ActiveRecord to not quote the default field?

I though about calling #execute with an “ALTER TABLE ADD COLUMN”
command, but from the sqlite3 docs:

The ADD [COLUMN] syntax is used to add a new column to an existing
table. The new column is always appended to the end of the list of
existing columns. Column-def may take any of the forms permissable in a
CREATE TABLE statement, with the following restrictions:

* The column may not have a PRIMARY KEY or UNIQUE constraint.
* The column may not have a default value of CURRENT_TIME, 

CURRENT_DATE or CURRENT_TIMESTAMP.
* If a NOT NULL constraint is specified, then the column must have a
default value other than NULL.

So I can’t do this, either…

Thanks,

Morgan