New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add `:expression` option support on the schema default #20005

Merged
merged 3 commits into from Jan 16, 2016

Conversation

Projects
None yet
6 participants
@kamipo
Member

kamipo commented May 4, 2015

Currently, it supports default expression (or function) only :uuid.

This PR adds expression support on the schema default for not only :uuid.

Example:

create_table :posts do |t|
  t.datetime :published_at, default: -> { 'NOW()' }
end

@kamipo kamipo force-pushed the kamipo:default_expression_support branch 4 times, most recently from 4f5d371 to 373c5e0 May 4, 2015

@kamipo kamipo force-pushed the kamipo:default_expression_support branch 2 times, most recently from 4232e07 to 4e86562 May 16, 2015

@kamipo kamipo force-pushed the kamipo:default_expression_support branch 3 times, most recently from c4206c4 to d87fadc May 27, 2015

@kamipo kamipo force-pushed the kamipo:default_expression_support branch 3 times, most recently to 5b3b20b Jun 13, 2015

@kamipo kamipo force-pushed the kamipo:default_expression_support branch from 5b3b20b to 5dfe057 Jun 20, 2015

@kamipo kamipo force-pushed the kamipo:default_expression_support branch from 5dfe057 to 3ae9a6f Aug 4, 2015

@kamipo kamipo force-pushed the kamipo:default_expression_support branch from 3ae9a6f to 5c2967c Sep 18, 2015

@jeremy

This comment has been minimized.

Member

jeremy commented Sep 20, 2015

Nice work! We have a :default option that covers other cases for column defaults, so it's confusing to have a separate :expression option that's also a column default with a different kind of value.

Can we use :default for arbitrary expressions, too? Perhaps default: { expression: … } or default: SqlLiteral.new('…').

@kamipo kamipo force-pushed the kamipo:default_expression_support branch from 5c2967c Sep 20, 2015

@pixeltrix

This comment has been minimized.

Member

pixeltrix commented Oct 12, 2015

What about supporting procs and the output from that is used raw?, e.g:

create_table :posts do |t|
  t.datetime :published_at, default: -> { 'NOW()' }
end

@kamipo kamipo force-pushed the kamipo:default_expression_support branch Oct 12, 2015

@kamipo

This comment has been minimized.

Member

kamipo commented Oct 12, 2015

@pixeltrix Looks nice! I changed to using procs.

@kamipo kamipo force-pushed the kamipo:default_expression_support branch 2 times, most recently Oct 13, 2015

@kamipo

This comment has been minimized.

Member

kamipo commented Oct 13, 2015

r? @jeremy

@kamipo kamipo force-pushed the kamipo:default_expression_support branch 2 times, most recently Oct 24, 2015

@sproot

This comment has been minimized.

sproot commented Oct 24, 2015

👍 +100500

@kamipo kamipo force-pushed the kamipo:default_expression_support branch Nov 7, 2015

@kamipo kamipo force-pushed the kamipo:default_expression_support branch Nov 15, 2015

@kamipo kamipo force-pushed the kamipo:default_expression_support branch 2 times, most recently Nov 23, 2015

@kamipo kamipo force-pushed the kamipo:default_expression_support branch 3 times, most recently Dec 19, 2015

@kamipo kamipo force-pushed the kamipo:default_expression_support branch Jan 5, 2016

@maclover7

This comment has been minimized.

Member

maclover7 commented Jan 10, 2016

Please rebase.

@kamipo kamipo force-pushed the kamipo:default_expression_support branch Jan 10, 2016

@kamipo

This comment has been minimized.

Member

kamipo commented Jan 10, 2016

Rebased!

kamipo added some commits May 3, 2015

Add expression support on the schema default
Example:

    create_table :posts do |t|
      t.datetime :published_at, default: -> { 'NOW()' }
    end
Fix extract default with CURRENT_DATE
The default 'now'::date is CURRENT_DATE.

@kamipo kamipo force-pushed the kamipo:default_expression_support branch to 744552f Jan 13, 2016

rafaelfranca added a commit that referenced this pull request Jan 16, 2016

Merge pull request #20005 from kamipo/default_expression_support
Add `:expression` option support on the schema default

@rafaelfranca rafaelfranca merged commit de22597 into rails:master Jan 16, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@kamipo kamipo deleted the kamipo:default_expression_support branch Jan 16, 2016

prathamesh-sonpatki added a commit to prathamesh-sonpatki/rails that referenced this pull request Jan 20, 2016

rafaelfranca added a commit that referenced this pull request Jan 20, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment