Go over our database update statements and exclude created_at updates
When I was working on #996 (closed), I realised that our
dbmodel.Update... calls may be wrongly updating the
created_at columns. It becomes apparent when you have an instance in the database and, instead of getting it before the update from the database, you create a sibling instance and attempt to use it in the update. In that case, you typically don't set the
created_at value and it defaults to nil. As a result,
go-pg will try to set the nil value which is prohibited due to the
NOT NULL constraint.
In general, the updates should not modify this timestamp. Therefore, the
created_at column should be excluded from the update statement, like this:
result, err := tx.Model(host).WherePK().ExcludeColumn("created_at").Update()
I think we're lucky we haven't hit this issue before.