Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 20, 2025

Replaces Kysely with Drizzle ORM for improved type safety and developer experience while maintaining SQLite + better-sqlite3 as the database driver.

Core Changes

Database Layer

  • Created Drizzle schema in src/lib/schema.ts with type exports for all 8 tables
  • Replaced Kysely query builder with Drizzle's type-safe query API
  • Kept better-sqlite3 driver (initially attempted @libsql/client but SQL parser failed on [ in markdown content)
  • Maintained custom SQL functions (regexp, uuid, slugify) via better-sqlite3 registration

Type System

  • Changed published field from number (0/1) to boolean across schema, queries, and UI
  • Updated PostType and PaginatedPosts interfaces
  • Removed dependency on kysely-codegen in favor of Drizzle's inferred types

Query Migration
Updated 13 files to use Drizzle syntax:

// Before (Kysely)
const posts = await db
  .selectFrom("posts")
  .select(["id", "title"])
  .where("published", "=", 1)
  .execute();

// After (Drizzle)
const posts = await db
  .select({ id: schema.posts.id, title: schema.posts.title })
  .from(schema.posts)
  .where(eq(schema.posts.published, true));

Migration System

  • Simplified to use exec() for multi-statement SQL (better-sqlite3 native method)
  • Removed complex SQL parsing logic - migrations now run atomically via transactions
  • Kept existing migration files unchanged

Developer Experience

  • Added Drizzle Kit scripts: drizzle:generate, drizzle:push, drizzle:studio
  • Removed typegen script (types now inferred from schema)
  • Updated build to use --skipLibCheck to avoid Drizzle's internal type complexity

Files Changed

  • Database: src/lib/database.ts, src/lib/schema.ts (new), src/lib/migrations.ts
  • Models: src/models/posts.ts, src/app/posts/types.ts
  • Auth: src/lib/auth.ts
  • Pages: All dashboard routes, post routes, journal, login
  • API: posts/sync, posts/uploads, sitemap.xml
  • UI: Post form components, dashboard pages
Original prompt

Migrate to libsql + drizzle


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits November 20, 2025 15:26
Co-authored-by: ncrmro <8276365+ncrmro@users.noreply.github.com>
Co-authored-by: ncrmro <8276365+ncrmro@users.noreply.github.com>
Co-authored-by: ncrmro <8276365+ncrmro@users.noreply.github.com>
Copilot AI changed the title [WIP] Migrate database to libsql and drizzle Migrate from Kysely to Drizzle ORM Nov 20, 2025
Copilot AI requested a review from ncrmro November 20, 2025 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants