Skip to content

Commit 8695b02

Browse files
authored
Merge pull request rails#27978 from kamipo/add_blob_short_hand_method
Add `blob` short-hand method for schema creation
2 parents ec5c898 + f601908 commit 8695b02

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ def primary_key(name, type = :primary_key, **options)
249249
define_column_methods :bigint, :binary, :boolean, :date, :datetime, :decimal,
250250
:float, :integer, :json, :string, :text, :time, :timestamp, :virtual
251251

252+
alias :blob :binary
252253
alias :numeric :decimal
253254
end
254255

@@ -564,6 +565,7 @@ def add_column(name, type, **options)
564565
# t.time
565566
# t.date
566567
# t.binary
568+
# t.blob
567569
# t.boolean
568570
# t.foreign_key
569571
# t.json

activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ def drop_table(table_name, **options)
523523
# <tt>:primary_key</tt>, <tt>:string</tt>, <tt>:text</tt>,
524524
# <tt>:integer</tt>, <tt>:bigint</tt>, <tt>:float</tt>, <tt>:decimal</tt>, <tt>:numeric</tt>,
525525
# <tt>:datetime</tt>, <tt>:time</tt>, <tt>:date</tt>,
526-
# <tt>:binary</tt>, <tt>:boolean</tt>.
526+
# <tt>:binary</tt>, <tt>:blob</tt>, <tt>:boolean</tt>.
527527
#
528528
# You may use a type not in this list as long as it is supported by your
529529
# database (for example, "polygon" in MySQL), but this will not be database
@@ -532,7 +532,7 @@ def drop_table(table_name, **options)
532532
# Available options are (none of these exists by default):
533533
# * <tt>:limit</tt> -
534534
# Requests a maximum column length. This is the number of characters for a <tt>:string</tt> column
535-
# and number of bytes for <tt>:text</tt>, <tt>:binary</tt>, and <tt>:integer</tt> columns.
535+
# and number of bytes for <tt>:text</tt>, <tt>:binary</tt>, <tt>:blob</tt>, and <tt>:integer</tt> columns.
536536
# This option is ignored by some backends.
537537
# * <tt>:default</tt> -
538538
# The column's default value. Use +nil+ for +NULL+.

activerecord/test/cases/schema_dumper_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ def test_schema_dump_does_not_include_limit_for_float_field
238238
assert_match %r{t\.float\s+"temperature"$}, output
239239
end
240240

241+
def test_schema_dump_aliased_types
242+
output = standard_dump
243+
assert_match %r{t\.binary\s+"blob_data"$}, output
244+
assert_match %r{t\.decimal\s+"numeric_number"}, output
245+
end
246+
241247
if ActiveRecord::Base.connection.supports_expression_index?
242248
def test_schema_dump_expression_indices
243249
index_definition = dump_table_schema("companies").split(/\n/).grep(/t\.index.*company_expression_index/).first.strip

activerecord/test/schema/schema.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
t.string :name
8787
t.binary :data
8888
t.binary :short_data, limit: 2048
89+
t.blob :blob_data
8990
end
9091

9192
create_table :birds, force: true do |t|
@@ -652,6 +653,7 @@
652653
t.decimal :my_house_population, precision: 2, scale: 0
653654
t.decimal :decimal_number
654655
t.decimal :decimal_number_with_default, precision: 3, scale: 2, default: 2.78
656+
t.numeric :numeric_number
655657
t.float :temperature
656658
t.decimal :decimal_number_big_precision, precision: 20
657659
# Oracle/SQLServer supports precision up to 38

0 commit comments

Comments
 (0)