Skip to content

Column defaults are displayed as String unexpectedly #762

Closed
@pocke

Description

@pocke

Since v3.1.0, we got incorrect default values by annotate_models.

It is a part of our diff between v3.0.3 and v3.1.0.

-#  comments_count             :integer          default(0), not null
-#  comment_users_unique_count :integer          default(0), not null
-#  coediting                  :boolean          default(FALSE), not null
+#  comments_count             :integer          default("0"), not null
+#  comment_users_unique_count :integer          default("0"), not null
+#  coediting                  :boolean          default("false"), not null

And a part of schema.rb for the columns definitions.

    t.integer "comments_count", default: 0, null: false
    t.integer "comment_users_unique_count", default: 0, null: false
    t.boolean "coediting", default: false, null: false

I guess it depends on RDBMS because the spec is not wrong.
We use PostgreSQL.

Probably this pull request is related. #677

Commands

$ bin/rake annotate_models

And I investigated the ActiveRecord::ConnectionAdapters::PostgreSQLColumn#default returned value, which is used by #677, and klass.column_defaults[column.name], which was used previously.

$ bin/rails console

> klass.columns.find{|x| x.name == 'comments_count'}.default
=> "0"
> klass.column_defaults["comments_count"]
=> 0

Version

  • annotate version: v3.1.0
  • rails version: 5.2.4.1
  • ruby version: 2.6.4

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions