Skip to content

Commit cffeebf

Browse files
author
CloudLobster
committed
fix: simplify ensureTable - use prepare().run(), no FK, no indexes
1 parent 6d9a581 commit cffeebf

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

worker/src/routes/world-id.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,17 @@ const worldId = new Hono<AppBindings>();
77

88
// ─── Auto-migrate: create table if not exists ───
99
async function ensureTable(db: D1Database) {
10-
try {
11-
await db.exec(`CREATE TABLE IF NOT EXISTS world_id_verifications (
12-
id TEXT PRIMARY KEY,
13-
handle TEXT NOT NULL,
14-
wallet TEXT NOT NULL,
15-
nullifier_hash TEXT NOT NULL UNIQUE,
16-
verification_level TEXT NOT NULL DEFAULT 'orb',
17-
credential_type TEXT,
18-
world_id_version TEXT NOT NULL DEFAULT 'v4',
19-
verified_at INTEGER NOT NULL DEFAULT (unixepoch()),
20-
FOREIGN KEY (handle) REFERENCES accounts(handle)
21-
)`);
22-
} catch (_) {}
23-
try {
24-
await db.exec(`CREATE INDEX IF NOT EXISTS idx_worldid_handle ON world_id_verifications(handle)`);
25-
} catch (_) {}
26-
try {
27-
await db.exec(`CREATE INDEX IF NOT EXISTS idx_worldid_nullifier ON world_id_verifications(nullifier_hash)`);
28-
} catch (_) {}
10+
// Simple table without foreign keys (D1 doesn't enforce FK anyway)
11+
await db.prepare(`CREATE TABLE IF NOT EXISTS world_id_verifications (
12+
id TEXT PRIMARY KEY,
13+
handle TEXT NOT NULL,
14+
wallet TEXT NOT NULL,
15+
nullifier_hash TEXT NOT NULL,
16+
verification_level TEXT NOT NULL DEFAULT 'orb',
17+
credential_type TEXT,
18+
world_id_version TEXT NOT NULL DEFAULT 'v4',
19+
verified_at INTEGER NOT NULL DEFAULT (unixepoch())
20+
)`).run();
2921
}
3022

3123
/**

0 commit comments

Comments
 (0)