Currently, there's no way in migrations or auto-migrations to specify
the use of a native function as the default for a column. As an
example of what I mean, I want something that can create the following
create table sql:
CREATE TABLE articles (
...
'created_at' timestamp DEFAULT NOW(),
)
Currently, if you attempt the obvious thing,
column :created_at, 'timestamp', :default => 'NOW()'
it quotes the 'NOW()' for you, and the string "NOW()" is not a valid
timestamp. I don't want to change the current behavior, because
specifying strings as default seems like the most normal case. I need
to come up with a new syntax for informing the sql generator to use a
native function, rather than a string.
Some ideas I've had so far:
# turn a symbol into a native function, a string into a default
column :created_at, 'timestamp', :default => :'NOW()'
# have a separate option
column :created_at, 'timestamp', :native_default => 'NOW()'
# detect a '()' at the end. this probably wont work in several
edge-y cases, though
column :fullname, 'varchar', :default => 'first_name || lastname'
# A magic function helper that informs the generator to not quote
the string
column :created_at, 'timestamp', :default => native('NOW()')
I like the last two the best, but I wanted to see what others thought,
or if they had any other ideas worth considering.
Paul
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---