Comments (7)
Whoops, I thought I responded to this a while back, but I guess I forgot to hit "send"!
I guess it depends on how it would impact configuration. Would we want to include/exclude that check separately? I would guess "yes". Checking for a presence validation is not the same thing as checking for an association column existing at all.
from database_consistency.
My first guess is it's a failure because the user_id column is missing on the payments table.
#<DatabaseConsistency::Checkers::ColumnPresenceChecker:0x000000010d9a0e58
@association=
#<ActiveRecord::Reflection::BelongsToReflection:0x000000010d551910
@active_record=Payment(id: uuid, fulfillable_type: string, fulfillable_id: uuid, checkout_payment_id: string, checkout_payment_data: jsonb, metadata: jsonb, created_at: datetime, updated_at: datetime),
@class_name="User",
@constructable=true,
@foreign_key="user_id",
@klass=
User(id: uuid),
@name=:user,
@options={},
@plural_name="users",
@scope=nil>,
@attribute=:user,
@checker_name="ColumnPresenceChecker",
@column_or_attribute_name="user",
@model=Payment(id: uuid, fulfillable_type: string, fulfillable_id: uuid, checkout_payment_id: string, checkout_payment_data: jsonb, metadata: jsonb, created_at: datetime, updated_at: datetime),
@regular_column=nil,
@table_or_model_name="Payment",
@validators=[#<ActiveRecord::Validations::PresenceValidator:0x000000010d548860 @attributes=[:user], @options={:message=>:required}>]>
create_table "payments", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t|
t.string "fulfillable_type"
t.uuid "fulfillable_id"
t.string "checkout_payment_id"
t.jsonb "checkout_payment_data", default: {}, null: false
t.jsonb "metadata", default: {}, null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["fulfillable_type", "fulfillable_id"], name: "index_payments_on_fulfillable"
end
create_table "users", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t|
...
end
from database_consistency.
Reproducible with this in column_presence_checker_spec:
context 'when the column for the `belongs_to` foreign key is missing' do
let(:attribute) { :user }
let(:klass) { define_class { |klass| klass.belongs_to :user, foreign_key: 'user_id', **required } }
before do
define_database do
create_table :entities
end
end
specify do
expect(checker.report(catch_errors: false)).to be_nil
end
end
from database_consistency.
Hi @asavageiv,
First, thank you for using the gem and reporting the issue! One more thank you for the contribution with the fixing PR!
As I can see, the root cause of the issue is an invalid association, is it?
Do you think we should just ignore it or report that the association is invalid?
Or do you think it should be a separate check instead?
from database_consistency.
I agree with you. We could introduce checkers for finding "dead"/invalid code.
Could you please address issues on your PR so I can merge it?
And, by the way, do you want to contribute with a separate checker for the issue we talked about?
from database_consistency.
Actually it already seems to be present in ForeignKeyTypeChecker. I got the following error:
ForeignKeyTypeChecker fail Payment user association (user) of class (Payment) relies on field (user_id) of table (payments) but it is missing
from database_consistency.
Oh, you're right. I think it would be good to extract it to a separate checker. Would you agree?
from database_consistency.
Related Issues (20)
- `EnumTypeChecker` is complaining about `enum` column HOT 4
- Misleading commandline help message HOT 3
- `ColumnPresenceChecker` and polymorphic association HOT 1
- `ColumnPresenceChecker`, `belongs_to `associations, and `optional`, `required` options HOT 3
- Checker that makes sure that enum type is used to store ActiveRecord's enums HOT 14
- EnumValueChecker doesn't work with ActiveRecord below 7 HOT 4
- Add ability to ignore certain namespaces HOT 5
- Does this gem recognize a find on a column without index? HOT 4
- database_consistency -f generates duplicate migrations HOT 3
- Inconsistency found in NullConstaintChecker HOT 3
- [Feature] Check constraint checker HOT 2
- Excluding Database Connections to Non Primary Databases Including sqlserver HOT 2
- Ensure that generated todo files are created with consistent ordering HOT 6
- MissingIndexChecker violation on polymorphic association HOT 3
- ForeignKeyCascadeChecker default mapping HOT 3
- UniqueIndexChecker and postgresql partial indexes HOT 1
- Extendable database_consistency HOT 5
- Checker for implicit_order_column for table with uuid as primary key HOT 8
- False-positive when index columns are defined as a string and not array HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from database_consistency.