Actually, I came up with a better way:
column :created_at, 'timestamp', :default => now
Thats it. I really like it because you can also do now() for that
extra bit of SQL-flavor.
This method makes a SqlExp object with a value of 'NOW()' that gets
to_s'd by the adapter, but gets skipped by the quoter because its not
a String.
Sam: about 3/4 of the adapters are marked with "TODO: move to dm-
migrations". When are we gonna do that? What does that mean for auto-
migration? Will it move into dm-migrations too? Does this need to be
done before 1.0? I can take charge of that, I now have a little more
time to devote to migrations again, and all the related stuff in core
is in a pretty sorry state.
On Sep 26, 3:39 pm, Sam Smoot <[EMAIL PROTECTED]> wrote:
> On Sep 26, 4:01 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> wrote:
>
>
>
> > 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
>
> The last definitely. Though it needs to take an Adapter type as well.
> Perhaps optionally. The reason is that we have the same problem with
> adapter specific queries and it would be nice to say: "Do this
> when :default is mapped to Sqlite3Adapter on development, but that
> when it's PostgresAdapter on production".
>
> But absolutely, the last option is best.
>
> -Sam
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---