| 1 | /** |
| 2 | * Bills every repository for log entries pushed before pushes were recorded (0035). Without --apply it only reports. Safe beside a running API and safe to rerun: rows are keyed by entry. |
| 3 | * node dist/scripts/backfill-storage-usage.js [--apply], after `nest build` |
| 4 | */ |
| 5 | import { type Database, |
| 6 | import { Module } |
| 7 | import { ConfigModule } |
| 8 | import { NestFactory } |
| 9 | |
| 10 | import { DATABASE, DatabaseModule |
| 11 | import { formatByteSize } |
| 12 | import { WalStoreService } |
| 13 | import { S3Service } |
| 14 | import { RepositoryLogBackfillService } |
| 15 | import { errorMessage } |
| 16 | |
| 17 | // Only what a backfill needs, so the script opens no HTTP or SSH listener and starts no poller. |
| 18 | @Module({ |
| 19 | imports: [ConfigModule.forRoot |
| 20 | providers: [RepositoryLogBackfillService, |
| 21 | }) |
| 22 | class BackfillModule {} |
| 23 | |
| 24 | const apply = process |
| 25 | |
| 26 | const app = await |
| 27 | logger: ['warn', |
| 28 | }); |
| 29 | const db = app |
| 30 | const backfill = app |
| 31 | |
| 32 | const repositories = await |
| 33 | .select({ id: |
| 34 | .from(schema.repository |
| 35 | |
| 36 | let failed = 0 |
| 37 | let total = 0 |
| 38 | for (const { id |
| 39 | try { |
| 40 | const rows = |
| 41 | if (rows.length |
| 42 | const bytes = |
| 43 | ? await backfill. |
| 44 | : rows.reduce( |
| 45 | total += bytes; |
| 46 | console.log(`${ |
| 47 | } catch (error) |
| 48 | failed++; |
| 49 | console.error(`${ |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | console.log( |
| 54 | `${apply ? ' |
| 55 | ); |
| 56 | await app.close() |
| 57 | process.exitCode = failed |