jesjos / jesjos/active_record_upsert

Columns with database defaults are not updated

Open
#98 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
207
Forks
49
PR merge metrics
No merged PRs in 30d

Description

We found that when

1) having a default in the database (here for a table called ``hardwares``)

┌─────────┬─────────────────┬────────
│ Column │ Type │ Default
├─────────┼─────────────────┼─────────
│ id │ integer │ ...
│ prio │ integer │ 999

2) having an existing entry in the database with a non default value for ``prio`` like: 998 with id: 1

That upserting like so:

hw = { id: 1, prio: 999 }
id = Hardware.new(prio: hw[:prio]).upsert.id

won't mention the ``prio`` column in the ``ON CONFLICT`` part resulting in no update. However, when upserting like so:

id = Hardware.upsert(prio: hw[:prio]).id

did indeed update the record in the database (back to its default value). Am not sure if this is (a bug/an issue), but thought I would drop this here. Thanks for all the work on the nice Gem!

Contributor guide

No contributing guide indexed for this repository

Research direction

No source files or tests are named. Start by reproducing the two upsert forms in the issue and inspect the generated ON CONFLICT behavior for database-default columns. Done means determining whether the discrepancy is a bug and, if confirmed, adding coverage that demonstrates consistent updating.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby, sql
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.