Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails/NotNullColumn suggesting default value for virtual column. #887

Closed
MrJoy opened this issue Dec 16, 2022 · 1 comment · Fixed by #892
Closed

Rails/NotNullColumn suggesting default value for virtual column. #887

MrJoy opened this issue Dec 16, 2022 · 1 comment · Fixed by #892

Comments

@MrJoy
Copy link

MrJoy commented Dec 16, 2022

Expected behavior

    add_column :google_calendar_instances,
               :effective_label,
               :virtual,
               type:   :string,
               as:     "COALESCE(label, summary)",
               stored: true,
               null:   false

Given this code in a migration, the idea of a default value for the column is somewhat nonsensical. I would expect the NotNullColumn cop to understand that default values should not be present for virtual columns.

Actual behavior

db/migrate/20221216223723_add_effective_label_to_google_calendar_instances.rb:11:16: C: Rails/NotNullColumn: Do not add a NOT NULL column without a default value.
               null:   false
               ^^^^^^^^^^^^^

Steps to reproduce the problem

See above code.

RuboCop version

1.40.0 (using Parser 3.1.3.0, rubocop-ast 1.24.0, running on ruby 3.1.3) [arm64-darwin21]
  - rubocop-graphql 0.18.0
  - rubocop-performance 1.15.1
  - rubocop-rails 2.17.3
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.16.0
  - rubocop-rubycw 0.1.6
  - rubocop-thread_safety 0.4.4
@MrJoy
Copy link
Author

MrJoy commented Jan 14, 2023

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant