1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #27978 from kamipo/add_blob_short_hand_method

Add `blob` short-hand method for schema creation
This commit is contained in:
Rafael França 2020-12-29 18:47:32 -05:00 committed by GitHub
commit 8695b02826
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 2 deletions

View file

@ -249,6 +249,7 @@ module ActiveRecord
define_column_methods :bigint, :binary, :boolean, :date, :datetime, :decimal,
:float, :integer, :json, :string, :text, :time, :timestamp, :virtual
alias :blob :binary
alias :numeric :decimal
end
@ -564,6 +565,7 @@ module ActiveRecord
# t.time
# t.date
# t.binary
# t.blob
# t.boolean
# t.foreign_key
# t.json

View file

@ -523,7 +523,7 @@ module ActiveRecord
# <tt>:primary_key</tt>, <tt>:string</tt>, <tt>:text</tt>,
# <tt>:integer</tt>, <tt>:bigint</tt>, <tt>:float</tt>, <tt>:decimal</tt>, <tt>:numeric</tt>,
# <tt>:datetime</tt>, <tt>:time</tt>, <tt>:date</tt>,
# <tt>:binary</tt>, <tt>:boolean</tt>.
# <tt>:binary</tt>, <tt>:blob</tt>, <tt>:boolean</tt>.
#
# You may use a type not in this list as long as it is supported by your
# database (for example, "polygon" in MySQL), but this will not be database
@ -532,7 +532,7 @@ module ActiveRecord
# Available options are (none of these exists by default):
# * <tt>:limit</tt> -
# Requests a maximum column length. This is the number of characters for a <tt>:string</tt> column
# and number of bytes for <tt>:text</tt>, <tt>:binary</tt>, and <tt>:integer</tt> columns.
# and number of bytes for <tt>:text</tt>, <tt>:binary</tt>, <tt>:blob</tt>, and <tt>:integer</tt> columns.
# This option is ignored by some backends.
# * <tt>:default</tt> -
# The column's default value. Use +nil+ for +NULL+.

View file

@ -238,6 +238,12 @@ class SchemaDumperTest < ActiveRecord::TestCase
assert_match %r{t\.float\s+"temperature"$}, output
end
def test_schema_dump_aliased_types
output = standard_dump
assert_match %r{t\.binary\s+"blob_data"$}, output
assert_match %r{t\.decimal\s+"numeric_number"}, output
end
if ActiveRecord::Base.connection.supports_expression_index?
def test_schema_dump_expression_indices
index_definition = dump_table_schema("companies").split(/\n/).grep(/t\.index.*company_expression_index/).first.strip

View file

@ -86,6 +86,7 @@ ActiveRecord::Schema.define do
t.string :name
t.binary :data
t.binary :short_data, limit: 2048
t.blob :blob_data
end
create_table :birds, force: true do |t|
@ -652,6 +653,7 @@ ActiveRecord::Schema.define do
t.decimal :my_house_population, precision: 2, scale: 0
t.decimal :decimal_number
t.decimal :decimal_number_with_default, precision: 3, scale: 2, default: 2.78
t.numeric :numeric_number
t.float :temperature
t.decimal :decimal_number_big_precision, precision: 20
# Oracle/SQLServer supports precision up to 38