fix(smartsheet): one-shot backfill script to re-add Entry IDs to manually inserted rows
Deploy to route.crispygoat.com / deploy (push) Failing after 3m59s
Deploy to route.crispygoat.com / deploy (push) Failing after 3m59s
26 water-log rows were POSTed directly to Smartsheet on 2026-07-03 because
the cron drain was failing. Those rows went in without Entry IDs, so the
next cron drain would have created duplicates (findRowByColumn returns
nothing when Entry ID is empty).
This script:
1. Matches each of the 26 hardcoded rows to a DB entry by
(headgate + irrigator + measurement + unit + logged_at).
2. Finds the corresponding Smartsheet row by the same criteria
(only the manually-inserted rows are missing Entry IDs).
3. PUTs the Entry ID back into the sheet row.
4. Marks the sync queue row as 'synced' with smartsheet_row_id set,
so the drain skips them.
5. Writes a sync log entry noting the manual backfill.
Idempotent: re-runs are no-ops. Wired into deploy.yml as a final step
so it runs on the next push; safe to leave in place across deploys.
Local invocation:
npm run smartsheet:backfill-entry-ids
This commit is contained in:
@@ -208,4 +208,27 @@ jobs:
|
||||
# newly added ones (like SMARTSHEET_*).
|
||||
ssh -o ConnectTimeout=60 -o StrictHostKeyChecking=no tyler@route.crispygoat.com "cd $APP_DIR && npm install --omit=dev 2>&1 | tail -5 && pm2 restart route-commerce --update-env || pm2 start npm --name route-commerce -- start -- -p 3100 && pm2 save && sleep 4 && curl -f -s http://localhost:3100/api/health/db-schema || { echo 'Health check failed after start - schema not applied (see plan)'; exit 1; }"
|
||||
|
||||
echo "Deployed successfully"
|
||||
echo "Deployed successfully"
|
||||
|
||||
# One-shot: fix the 2026-07-03 manual Smartsheet backfill that
|
||||
# bypassed the sync queue. This step is idempotent — it scans
|
||||
# for queue rows that are pending/failed with no smartsheet_row_id
|
||||
# and matches them to the 26 rows Tyler manually POSTed into the
|
||||
# sheet. It then PUTs the Entry ID back into each sheet row and
|
||||
# marks the queue rows as `synced` so the cron drain won't try to
|
||||
# re-create them. Safe to leave in place across deploys (re-runs
|
||||
# are no-ops once everything is synced). Remove this step once
|
||||
# the data has been verified in Smartsheet.
|
||||
- name: Smartsheet backfill entry-id fix
|
||||
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
|
||||
env:
|
||||
DATABASE_URL: ${{ secrets.DATABASE_URL }}
|
||||
SMARTSHEET_TOKEN_ENC_KEY: ${{ secrets.SMARTSHEET_TOKEN_ENC_KEY }}
|
||||
run: |
|
||||
set -e
|
||||
APP_DIR=/home/tyler/route-commerce
|
||||
ssh -o ConnectTimeout=15 -o StrictHostKeyChecking=no tyler@route.crispygoat.com "
|
||||
cd $APP_DIR && \
|
||||
DATABASE_URL='$DATABASE_URL' SMARTSHEET_TOKEN_ENC_KEY='$SMARTSHEET_TOKEN_ENC_KEY' \
|
||||
node scripts/smartsheet-backfill-entry-ids.mjs
|
||||
"
|
||||
Reference in New Issue
Block a user