You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simplest Possible Self-Contained Example Showing the Bug
require'sequel'require'logger'DB=Sequel.sqliteDB.loggers << Logger.new($stdout)DB.sql_log_level=:debugDB.create_table!(:artists)doprimary_key:idString:nameendDB.add_column(:artists,:uppername,:text,generated_always_as: Sequel.lit('upper(name)'))DB[:artists].insert(name: 'The Beatles')putsDB[:artists].first[:uppername]putsDB.schema(:artists)# uppername field isn't returned
It looks like the information was previously included, and a change to SQLite's table_xinfo PRAGMA to remove the GENERATED ALWAYS from the type broke it. It is trivial to reinclude the generated columns in the schema output:
diff --gita/lib/sequel/adapters/shared/sqlite.rbb/lib/sequel/adapters/shared/sqlite.rbindex355ab6c32..d1479612d100644
--- a/lib/sequel/adapters/shared/sqlite.rb
+++ b/lib/sequel/adapters/shared/sqlite.rb
@@ -504,7 +504,6 @@ moduleSequel# table_xinfo PRAGMA used, remove hidden columns# that are not generated columnsifrow[:generated]=(row.delete(:hidden) != 0)
- nextunlessrow[:type].end_with?(' GENERATED ALWAYS')row[:type]=row[:type].sub(' GENERATED ALWAYS','')endend
However, SQLite does not appear to provide an API to get the GENERATED AS VALUE (upper(name) in your example). It looks like the information is only available via accessing the sqlite_schema/sqlite_master system table, and you would have to parse it out of the CREATE TABLE SQL. One of Sequel's core tenets is that it never attempts to parse SQL, because it is generally impossible to do correctly in all cases.
So I will apply the patch so generated columns turn up in schema, but note that doing so doesn't provide enough information to rebuild the column. It's probably fine if you just plan to use Sequel::Model, but if you are trying to use the schema_dumper extension, it will not do what you want.
Complete Description of Issue
When calling the
schema
method, it doesn't return generated columns.Also, SQLite supports generated columns, however the documentation doesn't mention it
https://www.sqlite.org/gencol.html
https://sequel.jeremyevans.net/rdoc/classes/Sequel/Schema/CreateTableGenerator.html
Simplest Possible Self-Contained Example Showing the Bug
SQL Log (if any)
Ruby Version
3.2.2
Sequel Version
5.73.0
The text was updated successfully, but these errors were encountered: