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

missing_non_null_constraint: ignore database views #201

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading