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

Fix getting column default from VIEW in mysql #45067

Merged
merged 1 commit into from May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -159,7 +159,7 @@ def create_table_definition(name, **options)
end

def default_type(table_name, field_name)
match = create_table_info(table_name).match(/`#{field_name}` (.+) DEFAULT ('|\d+|[A-z]+)/)
match = create_table_info(table_name)&.match(/`#{field_name}` (.+) DEFAULT ('|\d+|[A-z]+)/)
default_pre = match[2] if match

if default_pre == "'"
Expand Down
5 changes: 3 additions & 2 deletions activerecord/test/cases/view_test.rb
Expand Up @@ -21,7 +21,7 @@ def setup
super
@connection = ActiveRecord::Base.connection
create_view "ebooks'", <<~SQL
SELECT id, name, status FROM books WHERE format = 'ebook'
SELECT id, name, cover, status FROM books WHERE format = 'ebook'
SQL
end

Expand Down Expand Up @@ -58,11 +58,12 @@ def test_views_ara_valid_data_sources
def test_column_definitions
assert_equal([["id", :integer],
["name", :string],
["cover", :string],
["status", :integer]], Ebook.columns.map { |c| [c.name, c.type] })
end

def test_attributes
assert_equal({ "id" => 2, "name" => "Ruby for Rails", "status" => 0 },
assert_equal({ "id" => 2, "name" => "Ruby for Rails", "cover" => "hard", "status" => 0 },
Ebook.first.attributes)
end

Expand Down