16### Backend (`/backend/`)
17- **index.ts**: Main Hono server with API routes
18- **database/**: SQLite database setup and queries
19- **routes/**: Modular route handlers
20- **auth/**: Authentication middleware and utilities
54 - `JWT_SECRET`: Secret for JWT token signing
55
562. The application will automatically create database tables on first run
57
583. Access the application at the HTTP endpoint URL
8 getUserByBearerToken,
9 updateBearerTokenLastUsed,
10} from "../database/queries.ts";
11import { requireAuth } from "./auth.ts";
12
141});
142
143// Debug endpoint to test database
144content.get("/debug", async (c) => {
145 try {
46 "slug": "codegen",
47 "link": "/blog/codegen",
48 "description": "Like Claude Artifacts, but with a backend and database",
49 "pubDate": "Thu, 22 Aug 2024 00:00:00 GMT",
50 "author": "JP Posma",
1---
2title: "Post-mortem: A Backward Incompatible Database Migration"
3description: Val runs failed due to a database migration that was not backward compatible
4pubDate: 2025-04-02T00:00:00.000Z
5author: Sophie Houser
6---
7
8Today at 10:11am we experienced a 12-minute outage, which caused HTTP vals to return 503 errors and other types of vals to fail. In the end, the root cause was a deployment timing issue where database migrations were deployed successfully, but our application code deployment hung for several minutes. The new database migrations were incompatible with the old application code and crashed the process.
9
10We aim to make all database migrations maintain backward compatibility, but in this case, we only discovered through the delayed deployment feedback that the new migrations were not compatible with previous versions.
11
12## Timeline
27## Next Steps
28
29Reliability is important to us and we’ve taken steps to make sure this doesn’t happen again. We’ve added a test to ensure database migrations are backward compatible, which we’ll run before we deploy any new code that includes database migrations.
20 updateUserLocation,
21 updateUserTokens,
22} from "./database/krogerQueries.ts";
23import { runMigrations } from "./database/migrations.ts";
24import { KrogerAuthService } from "./services/krogerAuth.ts";
25
26const app = new Hono();
27
28// Initialize database on startup
29await runMigrations();
30
2import { getCookie } from "https://esm.sh/hono@3.11.7/cookie";
3import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
4import { getUserById } from "../database/queries.ts";
5
6const staticRoutes = new Hono();
6 getContentItemById,
7 makeUserAdmin,
8} from "../database/queries.ts";
9import { requireAuth } from "./auth.ts";
10
30- [ ] add triggers to sidebar
31- [ ] add upload from SQL, CSV and JSON
32- [ ] add ability to connect to a non-val town Turso database
33- [x] fix wonky sidebar separator height problem (thanks to @stevekrouse)
34- [x] make result tables scrollable
17- **Method**: GET
18- **Response**: 1x1 transparent PNG image
19- **Side Effect**: Logs visitor information to database
20
21### Admin Dashboard
57- **Request Path**: Always `/sparkle.png`
58
59## Database Schema
60
61```sql
12const TRACKING_TABLE = 'pixel_tracking_logs';
13
14// Initialize database table
15async function initDatabase() {
16 await sqlite.execute(`CREATE TABLE IF NOT EXISTS ${TRACKING_TABLE} (
17 id INTEGER PRIMARY KEY AUTOINCREMENT,
24}
25
26// Initialize database on startup
27await initDatabase();
28
29// 1x1 transparent PNG pixel (base64 encoded)