database_consistency
database_consistency copied to clipboard
Incorrect numeric enum backing datatype - varchar/text
The problem only becomes apparent when prepared_statements:
option is set to false
. This is typical and recommended by Rails when connecting via PgBouncer.
ActiveRecord::StatementInvalid: PG::UndefinedFunction: ERROR: operator
does not exist: text = integer
LINE 1: SELECT "users".* FROM "users" WHERE "users"."os" = 0
# app/models/user.rb
enum os: [:linux, :windows]
# db/schema.rb
t.text "os"
The data actually saved in the column is '1'
, '2'
etc.
With prepared_statements: true
this error doesn't happen, and it works as expected (well, not really expected, I would expect it to blow up in both cases, but there's an implicit conversion somewhere along the way in statement preparation).
Should be easy to detect for both
enum os: [:linux, :windows]
and
enum os: { linux: 1, windows: 2}
definition options.