| 1 | -- A sandbox build's seconds are charged once billing confirms them |
| 2 | -- (`build_charged_at`); until then the sweep tries again, so a build is |
| 3 | -- never left uncharged by billing being briefly unreachable. Billing |
| 4 | -- records each build's reference (`deploy/<id>`) once, so a try whose |
| 5 | -- answer was lost cannot charge it twice. Builds that finished before this |
| 6 | -- were charged, or not, as they finished, and are not tried again. |
| 7 | ALTER TABLE deployments ADD COLUMN build_charged_at TEXT; |
| 8 | UPDATE deployments SET build_charged_at = 'before: charged as it finished' WHERE build_seconds IS NOT NULL; |
| 9 | CREATE INDEX IF NOT EXISTS deployments_build_uncharged ON deployments (finished_at) |
| 10 | WHERE build_charged_at IS NULL AND build_seconds > 0; |