Apply wahoo-route-update: PUT on re-push instead of duplicate POST

Re-pushing an edited route to Wahoo now updates the existing remote
route via PUT against the stored remote_id instead of POSTing a new
copy. external_id drops the version suffix and identifies the logical
route. sync_pushes is keyed by (user, route, provider) and tracks
last_pushed_version for the "local newer" UI state.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Ullrich Schäfer 2026-05-01 12:08:16 +02:00
parent 4853a116ff
commit db3eeed60f
No known key found for this signature in database
GPG key ID: A32FF691A0F752D9
14 changed files with 435 additions and 99 deletions

View file

@ -220,10 +220,11 @@ export const syncImports = journalSchema.table("sync_imports", {
});
// Tracks outbound route pushes to external providers (Wahoo today). One row
// per (user, route, version, provider) — push idempotency lives here. A row
// with `pushedAt` set means we have a confirmed remote_id and won't re-call
// the provider; a row with `error` set and no `pushedAt` is a failed attempt
// that can be retried in place.
// per (user, route, provider) — a logical Wahoo route is per-route, not
// per-version. `lastPushedVersion` records which local version is currently
// reflected on the remote side; `remoteId` lets subsequent pushes PUT in
// place. A row with `error` set and no `pushedAt` is a failed attempt that
// can be retried (POST if `remoteId` is null, PUT otherwise).
export const syncPushes = journalSchema.table(
"sync_pushes",
{
@ -234,20 +235,19 @@ export const syncPushes = journalSchema.table(
routeId: text("route_id")
.notNull()
.references(() => routes.id, { onDelete: "cascade" }),
routeVersion: integer("route_version").notNull(),
provider: text("provider").notNull(),
externalId: text("external_id").notNull(),
remoteId: text("remote_id"),
lastPushedVersion: integer("last_pushed_version"),
pushedAt: timestamp("pushed_at", { withTimezone: true }),
error: text("error"),
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
},
(t) => ({
userRouteVersionProviderUnique: uniqueIndex("sync_pushes_user_route_version_provider_unique").on(
userRouteProviderUnique: uniqueIndex("sync_pushes_user_route_provider_unique").on(
t.userId,
t.routeId,
t.routeVersion,
t.provider,
),
}),