Fix migration 050 on MySQL; add the estimate status column

- 050 wrote the kept rows' times back with their zone offset ('2026-10-31 10:06:08 -0400'), which MySQL
  refuses; dates and times are now written with Rails' quoted_date. Each record's delete and re-insert
  run in one transaction, so a failure can't leave it deleted.
- 051 adds estimates.txn_status for databases that ran migration 047 before that column was added to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
Claude committed 2026-10-31 11:52:32 -04:00
1 parent b739b84917
commit 6f40308029
2 files changed
+37 -3

No files matched your search

+15 -3
View File
@@ -43,10 +43,22 @@ class UniqueQboIds < ActiveRecord::Migration[7.0]
rows = select_all("SELECT * FROM #{quoted} WHERE id = #{quote(id)}").to_a
keep = rows.max_by { |row| [row['updated_at'].to_s, row.values.compact.size] }
columns = keep.keys
values = columns.map { |c| sql_value(keep[c]) }
execute "DELETE FROM #{quoted} WHERE id = #{quote(id)}"
execute "INSERT INTO #{quoted} (#{columns.map { |c| quote_column_name(c) }.join(', ')}) " \
"VALUES (#{columns.map { |c| quote(keep[c]) }.join(', ')})"
# Both or neither: a failed insert must not leave the record deleted
transaction do
execute "DELETE FROM #{quoted} WHERE id = #{quote(id)}"
execute "INSERT INTO #{quoted} (#{columns.map { |c| quote_column_name(c) }.join(', ')}) VALUES (#{values.join(', ')})"
end
end
end
# A value read back from the table, quoted for writing it again. Dates and times are formatted the way
# Rails writes them (e.g. '2026-10-31 14:06:08'), not with a time zone offset, which MySQL refuses.
def sql_value(value)
return 'NULL' if value.nil?
return quote(connection.quoted_date(value)) if value.is_a?(Time) || value.is_a?(Date) || value.is_a?(DateTime)
quote(value)
end
end