Repository navigation
Commit 34af214
authored
fix: owner-local dates and trimmed unit numbers (#1154)
Phase 66.3.1. After 18:00 CST, the database's UTC day is already
tomorrow. Owner reports, dashboard windows, late status and reversal
dates therefore ran a day ahead. Separately, unit numbers that differed
only in surrounding whitespace could both exist on one property.
## What changes
- **DATE-01:** the browser sends its local day as `p_today` to all 15
owner RPCs that read "today". `public.owner_local_day` accepts a day
within one day of UTC and otherwise falls back to the UTC day. That day
is part of every factory's query key, and `QUERY_CACHE_BUSTER` is v18.
- **DATE-02:** `reverse_charge` and `reverse_receipt` date reversals on
the owner's bounded day.
- **DATE-03:** cron and quota functions keep the UTC day on purpose,
documented in each body:
- `expire_leases` (23:00 UTC = 17:00 CST, the same calendar day);
- `generate_lease_rent_charges` (05:00 UTC; the charge dates come from
the period, so none is wrong);
- `queue_lease_reminders` (06:00 UTC = 00:00 CST, the same day);
- `meter_esign_send` and `get_esign_usage_current_month` (the e-sign
quota counts the UTC month, and the display matches the meter).
- No schedule changes.
- **UNIT-01:** `public.js_trim` trims exactly what JavaScript's
`String.prototype.trim` trims. Triggers store `units.unit_number` and
`properties.name` trimmed, and existing rows were backfilled behind a
guard that stops on a collision (0 found).
- **UNIT-02:** `units_property_unit_number_key` is rebuilt on
`lower(js_trim(unit_number))` under the same name.
- **Edge Functions:** `export-report` and `generate-pdf` read `today`
from the request, falling back to UTC, and pass `p_today`.
- **`db:types`:** now ignores the CLI's update notice, and the types are
regenerated in the CLI 3.4.0 format.
## Migrations (already applied to production, 2026-12-02 CST)
| File | Version |
|------|---------|
| owner_local_dates_dashboard | 20261203000149 |
| owner_local_dates_analytics | 20261203000405 |
| owner_local_dates_ledger_and_jobs | 20261203010229 |
| js_trim_units_properties | 20261203022837 |
The deployed client keeps working against them, because every new
parameter has a default.
Checks after the apply:
- md5 of each stored body against the file: 24 of 25 match. `js_trim`
holds its non-ASCII code points as literal characters instead of `\u`
escapes, introduced by the apply transport; its behaviour is identical
across 33 code points tested.
- Grant sweep: matches the plan, with anon false everywhere.
- A sweep for UTC-day reads finds only the documented exemption.
- Rolled-back probes behaved as expected.
- Integration tests: `rent-ledger-append-only` 10/10,
`units-unique-number` 7/7, `anon-rpc-grants` 35/35.
Chrome check at 20:39 CST (local 12-02, UTC 12-03): every owner-day
request on 10 pages carried `p_today: "2026-12-02"`, and Reports >
Expenses reads "Nothing spent Jan 1 to Dec 2, 2025".
## Known residuals
- Comparisons between a timestamptz column and the owner's day still cut
at UTC midnight. "newThisMonth" and "completedToday" are rendered
nowhere; the 30-day maintenance-trend boundary can be up to 6 hours off.
- `start_lease_ledger` uses `generate_lease_rent_charges`'s UTC month,
so next month's charge can appear up to 6 hours early on a month's last
evening.
- The comment inside the applied `generate_lease_rent_charges` body says
next month's charge can appear "up to 6 hours early". Via the 05:00 UTC
cron it is at most 1 hour early for Central owners; 6 hours applies only
to `start_lease_ledger`, and more in western zones. It is left as is,
because correcting it would need a production write.
- `formatDate` prints timestamptz values on their UTC day across about
27 files (tenants, inspections, applications, work orders). That is
recorded for a follow-up phase.
## Review
Four review cycles, with every finding fixed on this branch:
- **CI-only test failures:** four owner-day tests passed only on a
Central-time host. The unit suite is now pinned to America/Chicago in
`vitest.config.ts`, with a guard test.
- **UTC dates owners saw:** the `/reports/generate` file name, the
documents zip name, the dashboard's expiring-leases widget, and the
lease template's dates now use the owner's local day.
- **Test steadiness:** a reversal-date integration test no longer
depends on whether a run crosses UTC midnight.
- **Comments:** comments that claimed things the code does not do are
corrected.
The final cycle found no P0 or P1. The owner waived the second
consecutive clean cycle.
## After merge
Redeploy the two Edge Functions from `main` with explicit slugs:
```
SUPABASE_ACCESS_TOKEN=… bun scripts/deploy-edge-functions.ts export-report generate-pdf
```
Then verify with `get_edge_function`. Until that deploy, the live
functions call the RPCs without `p_today`, which is compatible. Rollback
order: roll Vercel back first, and never roll the database back while
the new client is live.
[hudsor01]161 files changed
Lines changed: 15751 additions & 614 deletions
File tree
- .github/workflows
- .planning
- phases/66.3.1-owner-local-dates-and-unit-whitespace
- prod-baseline
- scripts
- src
- app/(owner)
- analytics
- __tests__
- financial
- _components/__tests__
- overview
- property-performance
- __tests__
- reports
- __tests__
- generate/components
- __tests__
- components
- analytics
- __tests__
- dashboard
- documents
- __tests__
- ledger
- __tests__
- properties
- hooks
- __tests__
- api
- __tests__
- query-keys
- __tests__
- lib
- __tests__
- ledger
- reports
- __tests__
- templates
- __tests__
- providers
- __tests__
- types
- supabase
- functions
- __tests__
- export-report
- generate-pdf
- tests
- migrations
- tests/integration/rls
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
| |||
292 | 293 | | |
293 | 294 | | |
294 | 295 | | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
295 | 319 | | |
296 | 320 | | |
297 | 321 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
184 | 189 | | |
185 | 190 | | |
186 | 191 | | |
| |||
339 | 344 | | |
340 | 345 | | |
341 | 346 | | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
342 | 352 | | |
343 | 353 | | |
344 | 354 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
41 | 47 | | |
42 | 48 | | |
43 | 49 | | |
| |||
368 | 374 | | |
369 | 375 | | |
370 | 376 | | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
371 | 406 | | |
372 | 407 | | |
373 | 408 | | |
| |||
506 | 541 | | |
507 | 542 | | |
508 | 543 | | |
509 | | - | |
| 544 | + | |
510 | 545 | | |
511 | 546 | | |
512 | 547 | | |
| |||
520 | 555 | | |
521 | 556 | | |
522 | 557 | | |
| 558 | + | |
523 | 559 | | |
524 | 560 | | |
525 | 561 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | | - | |
13 | | - | |
14 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| |||
373 | 373 | | |
374 | 374 | | |
375 | 375 | | |
| 376 | + | |
0 commit comments