Giter Site home page Giter Site logo

Comments (7)

asavageiv avatar asavageiv commented on June 3, 2024 1

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.

asavageiv avatar asavageiv commented on June 3, 2024

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.

asavageiv avatar asavageiv commented on June 3, 2024

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.

djezzzl avatar djezzzl commented on June 3, 2024

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.

djezzzl avatar djezzzl commented on June 3, 2024

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.

asavageiv avatar asavageiv commented on June 3, 2024

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.

djezzzl avatar djezzzl commented on June 3, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.