mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix parsing expression for PostgreSQL generated column
This commit is contained in:
parent
67bffae6c7
commit
7fa2720b09
2 changed files with 9 additions and 1 deletions
|
@ -663,7 +663,12 @@ module ActiveRecord
|
||||||
column_name, type, default, notnull, oid, fmod, collation, comment, attgenerated = field
|
column_name, type, default, notnull, oid, fmod, collation, comment, attgenerated = field
|
||||||
type_metadata = fetch_type_metadata(column_name, type, oid.to_i, fmod.to_i)
|
type_metadata = fetch_type_metadata(column_name, type, oid.to_i, fmod.to_i)
|
||||||
default_value = extract_value_from_default(default)
|
default_value = extract_value_from_default(default)
|
||||||
|
|
||||||
|
if attgenerated.present?
|
||||||
|
default_function = default
|
||||||
|
else
|
||||||
default_function = extract_default_function(default_value, default)
|
default_function = extract_default_function(default_value, default)
|
||||||
|
end
|
||||||
|
|
||||||
if match = default_function&.match(/\Anextval\('"?(?<sequence_name>.+_(?<suffix>seq\d*))"?'::regclass\)\z/)
|
if match = default_function&.match(/\Anextval\('"?(?<sequence_name>.+_(?<suffix>seq\d*))"?'::regclass\)\z/)
|
||||||
serial = sequence_name_from_parts(table_name, column_name, match[:suffix]) == match[:sequence_name]
|
serial = sequence_name_from_parts(table_name, column_name, match[:suffix]) == match[:sequence_name]
|
||||||
|
|
|
@ -19,6 +19,8 @@ if ActiveRecord::Base.connection.supports_virtual_columns?
|
||||||
t.virtual :upper_name, type: :string, as: "UPPER(name)", stored: true
|
t.virtual :upper_name, type: :string, as: "UPPER(name)", stored: true
|
||||||
t.virtual :name_length, type: :integer, as: "LENGTH(name)", stored: true
|
t.virtual :name_length, type: :integer, as: "LENGTH(name)", stored: true
|
||||||
t.virtual :name_octet_length, type: :integer, as: "OCTET_LENGTH(name)", stored: true
|
t.virtual :name_octet_length, type: :integer, as: "OCTET_LENGTH(name)", stored: true
|
||||||
|
t.integer :column1
|
||||||
|
t.virtual :column2, type: :integer, as: "column1 + 1", stored: true
|
||||||
end
|
end
|
||||||
VirtualColumn.create(name: "Rails")
|
VirtualColumn.create(name: "Rails")
|
||||||
end
|
end
|
||||||
|
@ -78,6 +80,7 @@ if ActiveRecord::Base.connection.supports_virtual_columns?
|
||||||
assert_match(/t\.virtual\s+"upper_name",\s+type: :string,\s+as: "upper\(\(name\)::text\)", stored: true$/i, output)
|
assert_match(/t\.virtual\s+"upper_name",\s+type: :string,\s+as: "upper\(\(name\)::text\)", stored: true$/i, output)
|
||||||
assert_match(/t\.virtual\s+"name_length",\s+type: :integer,\s+as: "length\(\(name\)::text\)", stored: true$/i, output)
|
assert_match(/t\.virtual\s+"name_length",\s+type: :integer,\s+as: "length\(\(name\)::text\)", stored: true$/i, output)
|
||||||
assert_match(/t\.virtual\s+"name_octet_length",\s+type: :integer,\s+as: "octet_length\(\(name\)::text\)", stored: true$/i, output)
|
assert_match(/t\.virtual\s+"name_octet_length",\s+type: :integer,\s+as: "octet_length\(\(name\)::text\)", stored: true$/i, output)
|
||||||
|
assert_match(/t\.virtual\s+"column2",\s+type: :integer,\s+as: "\(column1 \+ 1\)", stored: true$/i, output)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_build_fixture_sql
|
def test_build_fixture_sql
|
||||||
|
|
Loading…
Reference in a new issue