fix(14): revise plans based on checker feedback

This commit is contained in:
2026-04-04 12:09:49 +02:00
parent 88708f962a
commit 30ec9b92d1
5 changed files with 140 additions and 79 deletions

View File

@@ -88,8 +88,8 @@ import * as schema from "../src/db/schema.ts";
```
**Environment variables:**
- `SQLITE_PATH` path to SQLite database file (default: `"gearbox.db"`)
- `DATABASE_URL` PostgreSQL connection string (required)
- `SQLITE_PATH` -- path to SQLite database file (default: `"gearbox.db"`)
- `DATABASE_URL` -- PostgreSQL connection string (required)
**Structure:**
1. Open SQLite database read-only
@@ -113,19 +113,19 @@ function intToBool(val: number | null): boolean {
**Migration order and transform functions for each table:**
1. **categories** `id` (serial), `name`, `icon`, `createdAt` (unixToDate)
2. **users** `id` (serial), `username`, `passwordHash`, `createdAt` (unixToDate)
3. **settings** `key`, `value` (no transforms needed, text PK)
4. **items** `id` (serial), `name`, `weightGrams`, `priceCents`, `categoryId`, `notes`, `productUrl`, `imageFilename`, `imageSourceUrl`, `quantity`, `createdAt` (unixToDate), `updatedAt` (unixToDate)
5. **threads** `id` (serial), `name`, `status`, `resolvedCandidateId`, `categoryId`, `createdAt` (unixToDate), `updatedAt` (unixToDate)
6. **sessions** `id` (text PK), `userId`, `expiresAt` (unixToDate)
7. **apiKeys** `id` (serial), `name`, `keyHash`, `keyPrefix`, `createdAt` (unixToDate)
8. **oauthClients** `id` (serial), `clientId`, `clientName`, `redirectUris`, `createdAt` (unixToDate)
9. **threadCandidates** `id` (serial), all fields, `createdAt`/`updatedAt` (unixToDate), `sortOrder` (keep as number)
10. **setups** `id` (serial), `name`, `createdAt`/`updatedAt` (unixToDate)
11. **oauthCodes** `id` (serial), all fields, `expiresAt` (unixToDate), `used` (intToBool)
12. **oauthTokens** `id` (serial), all fields, `expiresAt`/`refreshExpiresAt`/`createdAt` (unixToDate)
13. **setupItems** `id` (serial), `setupId`, `itemId`, `classification`
1. **categories** -- `id` (serial), `name`, `icon`, `createdAt` (unixToDate)
2. **users** -- `id` (serial), `username`, `passwordHash`, `createdAt` (unixToDate)
3. **settings** -- `key`, `value` (no transforms needed, text PK)
4. **items** -- `id` (serial), `name`, `weightGrams`, `priceCents`, `categoryId`, `notes`, `productUrl`, `imageFilename`, `imageSourceUrl`, `quantity`, `createdAt` (unixToDate), `updatedAt` (unixToDate)
5. **threads** -- `id` (serial), `name`, `status`, `resolvedCandidateId`, `categoryId`, `createdAt` (unixToDate), `updatedAt` (unixToDate)
6. **sessions** -- `id` (text PK), `userId`, `expiresAt` (unixToDate)
7. **apiKeys** -- `id` (serial), `name`, `keyHash`, `keyPrefix`, `createdAt` (unixToDate)
8. **oauthClients** -- `id` (serial), `clientId`, `clientName`, `redirectUris`, `createdAt` (unixToDate)
9. **threadCandidates** -- `id` (serial), all fields, `createdAt`/`updatedAt` (unixToDate), `sortOrder` (keep as number)
10. **setups** -- `id` (serial), `name`, `createdAt`/`updatedAt` (unixToDate)
11. **oauthCodes** -- `id` (serial), all fields, `expiresAt` (unixToDate), `used` (intToBool)
12. **oauthTokens** -- `id` (serial), all fields, `expiresAt`/`refreshExpiresAt`/`createdAt` (unixToDate)
13. **setupItems** -- `id` (serial), `setupId`, `itemId`, `classification`
**For each table, use this pattern:**
```typescript
@@ -197,7 +197,7 @@ main().catch((err) => {
```
</action>
<verify>
<automated>test -f scripts/migrate-sqlite-to-postgres.ts && grep -q "bun:sqlite" scripts/migrate-sqlite-to-postgres.ts && grep -q "postgres" scripts/migrate-sqlite-to-postgres.ts && grep -q "setval" scripts/migrate-sqlite-to-postgres.ts && grep -q "unixToDate\|unix.*Date\|\\* 1000" scripts/migrate-sqlite-to-postgres.ts && echo "PASS" || echo "FAIL"</automated>
<automated>test -f scripts/migrate-sqlite-to-postgres.ts && grep -q "bun:sqlite" scripts/migrate-sqlite-to-postgres.ts && grep -q "postgres" scripts/migrate-sqlite-to-postgres.ts && grep -q "setval" scripts/migrate-sqlite-to-postgres.ts && grep -q "unixToDate\|unix.*Date\|\\* 1000" scripts/migrate-sqlite-to-postgres.ts && bun run lint 2>&1 | tail -3 && echo "PASS" || echo "FAIL"</automated>
</verify>
<acceptance_criteria>
- scripts/migrate-sqlite-to-postgres.ts exists
@@ -221,10 +221,11 @@ main().catch((err) => {
- `bun run scripts/migrate-sqlite-to-postgres.ts --help` or similar does not crash on syntax errors (will fail on missing DATABASE_URL, which is expected)
- Script contains all 13 table migrations
- Script resets sequences for all tables with serial IDs
- `bun run lint` passes
</verification>
<success_criteria>
One-time migration script exists, handles all type conversions (timestamps, booleans), preserves IDs, resets sequences. Can be run with `DATABASE_URL=... SQLITE_PATH=... bun run scripts/migrate-sqlite-to-postgres.ts`.
One-time migration script exists, handles all type conversions (timestamps, booleans), preserves IDs, resets sequences. Can be run with `DATABASE_URL=... SQLITE_PATH=... bun run scripts/migrate-sqlite-to-postgres.ts`. Lint passes.
</success_criteria>
<output>