Skip to content
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

@kamipo
Copy link
Member

@kamipo 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
Copy link
Member

@jeremy 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
Copy link
Member

@pixeltrix 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
Copy link
Member Author

@kamipo 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
Copy link
Member Author

@kamipo 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
Copy link

@sproot 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
Copy link
Member

@maclover7 maclover7 commented Jan 10, 2016

Please rebase.

@kamipo kamipo force-pushed the kamipo:default_expression_support branch Jan 10, 2016
@kamipo
Copy link
Member Author

@kamipo kamipo commented Jan 10, 2016

Rebased!

kamipo added 3 commits May 3, 2015
Example:

    create_table :posts do |t|
      t.datetime :published_at, default: -> { 'NOW()' }
    end
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
Add `:expression` option support on the schema default
@rafaelfranca rafaelfranca merged commit de22597 into rails:master Jan 16, 2016
1 check passed
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
@shubham-sodel
Copy link

@shubham-sodel shubham-sodel commented Feb 13, 2020

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

If I want to add default time as current time + 90 minutes (1 an half hour ) then how we can do that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

7 participants