My rails application has a Rates model, which consists of many different table/references for each column. The only real variable is my Cost column (i input a dollar amount) and the default created_at and updated_at columns.
In my Rates index, currently i show all of the currently existing rates, model and schema below:
Rates Table
create_table "rates", force: :cascade do |t|
t.integer "origin_id"
t.integer "destination_id"
t.integer "carrier_id"
t.integer "shipment_category_id"
t.decimal "cost", precision: 10, scale: 2
t.integer "unit_of_measure_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "seller_id"
t.index ["carrier_id"], name: "index_rates_on_carrier_id", using: :btree
t.index ["destination_id"], name: "index_rates_on_destination_id", using: :btree
t.index ["origin_id"], name: "index_rates_on_origin_id", using: :btree
t.index ["seller_id"], name: "index_rates_on_seller_id", using: :btree
t.index ["shipment_category_id"], name: "index_rates_on_shipment_category_id", using: :btree
t.index ["unit_of_measure_id"], name: "index_rates_on_unit_of_measure_id", using: :btree
Rates Model
belongs_to :origin, :class_name => 'Port'
belongs_to :destination, :class_name => 'Port'
belongs_to :seller, :class_name => 'Carrier'
belongs_to :carrier
belongs_to :shipment_category
belongs_to :unit_of_measure
I was going to create a migration using this solution i found ( https://stackoverflow.com/a/34425284/7631715).
The thing is, i don't want this to stop me from importing "duplicate" data later. Since the rates from different Sellers (seller_id) change over time, i wanted to keep that data, so later i could make a line chart to see the cost variation over time.
Essentially my end product i want my page, (index) just to show the rates that are not duplicates, and if there are duplicated, only show the lasted added / created rates (last created, would be the current valid rate.)
Do i even bother creating that migration to add the uniqueness / constraint? Or should i just do this at the controller level. If controller, how would i go about that?
Thanks,