Skip to content

Commit

Permalink
missing_non_null_constraint: ignore database views (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima authored Jan 11, 2025
1 parent 88c85d0 commit 70bf5ad
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion active_record_doctor.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ Gem::Specification.new do |s|
s.add_development_dependency "rake", "~> 13.2.1"
s.add_development_dependency "rubocop", "~> 1.68.0"
s.add_development_dependency "sqlite3", "~> 2.2.0"
s.add_development_dependency "transient_record", "~> 2.0.0"
s.add_development_dependency "transient_record", "~> 3.0.0"
end
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ def message(column:, table:)

def detect
table_models = models.select(&:table_exists?).group_by(&:table_name)
views = connection.views

table_models.each do |table, models|
next if ignored?(table, config(:ignore_tables))
next if views.include?(table)

concrete_models = models.reject do |model|
model.abstract_class? || sti_base_model?(model)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,24 @@ def test_not_null_check_constraint
refute_problems
end

def test_views_are_ignored
Context.create_table(:old_comments, force: true) do |t|
t.integer :user_id
end

Context.execute(<<-SQL)
CREATE VIEW comments AS SELECT * FROM old_comments
SQL

Context.define_model(:Comment) do
belongs_to :user, required: true
end

refute_problems
ensure
Context.execute("DROP VIEW comments")
end

def test_config_ignore_tables
Context.create_table(:users) do |t|
t.string :name, null: true
Expand Down

0 comments on commit 70bf5ad

Please sign in to comment.