Skip to content

Commit

Permalink
Merge pull request #46939 from fatkodima/fix-dumping-virtual-columns
Browse files Browse the repository at this point in the history
Fix schema cache dumping of virtual columns
  • Loading branch information
byroot committed Apr 20, 2023
1 parent 629d981 commit 302aa41
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ def sql_type

def init_with(coder)
@serial = coder["serial"]
@generated = coder["generated"]
super
end

def encode_with(coder)
coder["serial"] = @serial
coder["generated"] = @generated
super
end

Expand Down
19 changes: 19 additions & 0 deletions railties/test/application/rake/dbs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,25 @@ def db_schema_cache_dump
db_schema_cache_dump
end

test "db:schema:cache:dump dumps virtual columns" do
Dir.chdir(app_path) do
use_postgresql(database_name: "railties_db")
rails "db:drop", "db:create"

rails "runner", <<~RUBY
ActiveRecord::Base.connection.create_table(:books) do |t|
t.integer :pages
t.virtual :pages_plus_1, type: :integer, as: "pages + 1", stored: true
end
RUBY

rails "db:schema:cache:dump"

virtual_column_exists = rails("runner", "p ActiveRecord::Base.connection.schema_cache.columns('books')[2].virtual?").strip
assert_equal "true", virtual_column_exists
end
end

def db_fixtures_load(expected_database)
Dir.chdir(app_path) do
rails "generate", "model", "book", "title:string"
Expand Down

0 comments on commit 302aa41

Please sign in to comment.