Skip to content

Commit

Permalink
Make generated columns show up in Database#schema when using SQLite 3…
Browse files Browse the repository at this point in the history
….37+ (Fixes #2087)

Sequel's approach apparently broke in SQLite 3.37 or 3.38, and
771c1d1 was committed to work
around the issue in the specs without actually fixing it.
  • Loading branch information
jeremyevans committed Oct 13, 2023
1 parent b196221 commit 44f6b8b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
=== master

* Make generated columns show up in Database#schema when using SQLite 3.37+ (jeremyevans) (#2087)

* Add revert method for Sequel.migration blocks, to revert changes inside the block on up, and apply the changes on down (jeremyevans)

* Re-add is_json and is_not_json methods to the pg_json_ops extension, as the support was re-added in PostgreSQL 16 (jeremyevans)
Expand Down
1 change: 0 additions & 1 deletion lib/sequel/adapters/shared/sqlite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,6 @@ def parse_pragma(table_name, opts)
# table_xinfo PRAGMA used, remove hidden columns
# that are not generated columns
if row[:generated] = (row.delete(:hidden) != 0)
next unless row[:type].end_with?(' GENERATED ALWAYS')
row[:type] = row[:type].sub(' GENERATED ALWAYS', '')
end
end
Expand Down
5 changes: 1 addition & 4 deletions spec/adapters/sqlite_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,7 @@
@db.create_table!(:fk){Integer :a; Integer :b; Integer :c, :generated_always_as=>Sequel[:a] * 2 + :b + 1; Integer :d, :generated_always_as=>Sequel[:a] * 2 + :b + 2, :generated_type=>:stored; ; Integer :e, :generated_always_as=>Sequel[:a] * 2 + :b + 3, :generated_type=>:virtual}
@db[:fk].insert(:a=>100, :b=>10)
@db[:fk].select_order_map([:a, :b, :c, :d, :e]).must_equal [[100, 10, 211, 212, 213]]

# Generated columns do not show up in schema on SQLite 3.37.0 (or maybe 3.38.0)
expected = DB.sqlite_version >= 33700 ? [false, false] : [false, false, true, true, true]
@db.schema(:fk).map{|_,v| v[:generated]}.must_equal expected
@db.schema(:fk).map{|_,v| v[:generated]}.must_equal [false, false, true, true, true]
end if DB.sqlite_version >= 33100
end

Expand Down

0 comments on commit 44f6b8b

Please sign in to comment.