key value violates unique constraint "index_authors_on_name" DETAIL: Key (title)=(Mr. Duplicate) already exists This error is thrown every time the Active Record validation is bypassed
Incoherent Data can still be introduced. Database level index on unique makes sure data is never duplicated. Rails will skip validations a lot in concurrent situations, so always handle the underlying ActiveRecord::RecordNotUnique Error. Don’t forget to add unique index on one-to-one relationships.
associations. Referential Integrity is compromised when we use this ActiveRecord pattern. Expensive to index. The data distribution isn’t usually uniform. Harder to JOIN in SQL.
integrity. Foreign keys can be added. Extract similar behaviors using modules in Ruby in the application. Create a non-table backed Ruby class for creating comments Use class_name option to designate which class name to use when retrieving records.
all comments regardless of type. More expensive to add another parent type. Use specific tables if you care for data integrity. If data integrity is a non-issue, use polymorphic associations. Event logging or activity feeds are good examples.
errors = [] Post.find_each do |post| next if post.valid? errors << [post.id, post.errors.full_messages] break if errors.size > MAX_ERRORS end assert_equal [], errors end
you have bad data already Reactive integrity checks are a good alternative Run these regularly against production data to surface errors up. Avoid using complex constraints.