All checks were successful
Run Check Script / check (pull_request) Successful in 2m15s
`physical_hosts.version_id` is `Id::default().to_string()`, which
formats `{masked_hex_timestamp}_{rand7}`. Two problems for using that
as a "latest row" key:
1. `format!("{:x}", v)` is variable-length. When the masked 24-bit
clock crosses a hex-width boundary (every few days at most, ±18h
or 12 days from cycle start), lexicographic comparison breaks:
`'_'` (0x5F) > any digit, so "1234_…" sorts HIGHER than
"123456_…" even though the latter was saved later.
2. The timestamp is masked to 24 bits, wrapping every ~194 days.
Net effect: `MAX(version_id)` in get_all_hosts / get_latest_by_id /
save's dedupe lookup can return an OLD row instead of the most
recently inserted one — exactly the "stale IP in the Select" the user
reported after re-adding a previously-deleted node.
Fix: order by SQLite's implicit `rowid` instead — strictly monotonic
INSERT counter, always reflects real save order. physical_hosts is
not WITHOUT ROWID, so rowid is always there. The version_id column
stays on every row (useful in the UI / audit logs) but no longer
drives ranking.
Id::default() is untouched; it's used throughout the codebase and
fixing the format is a separate, wider change.
sqlx offline cache regenerated.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
33 lines
993 B
JSON
33 lines
993 B
JSON
{
|
|
"db_name": "SQLite",
|
|
"query": "\n SELECT\n p1.id,\n p1.version_id,\n p1.data as \"data: Json<PhysicalHost>\"\n FROM\n physical_hosts p1\n INNER JOIN (\n SELECT\n id,\n MAX(rowid) AS max_rowid\n FROM\n physical_hosts\n GROUP BY\n id\n ) p2 ON p1.id = p2.id AND p1.rowid = p2.max_rowid\n ",
|
|
"describe": {
|
|
"columns": [
|
|
{
|
|
"name": "id",
|
|
"ordinal": 0,
|
|
"type_info": "Text"
|
|
},
|
|
{
|
|
"name": "version_id",
|
|
"ordinal": 1,
|
|
"type_info": "Text"
|
|
},
|
|
{
|
|
"name": "data: Json<PhysicalHost>",
|
|
"ordinal": 2,
|
|
"type_info": "Null"
|
|
}
|
|
],
|
|
"parameters": {
|
|
"Right": 0
|
|
},
|
|
"nullable": [
|
|
false,
|
|
false,
|
|
false
|
|
]
|
|
},
|
|
"hash": "8dfce6f15a95a44f5899e2953cfc56d8d1b34fe36615edcf3fed08dd81aefa7a"
|
|
}
|