feat(db): add Drizzle ORM with local SQLite storage

Configure Bun SQLite with WAL mode, foreign keys, and a shared database path for development and production.

Add migration commands and startup migration handling, check database connectivity in the health endpoint, and document configuration while excluding local database files from Git.
This commit is contained in:
syntaxbullet
2026-09-04 07:50:14 +02:00
parent 23e9f4c717
commit 29bf75760b
13 changed files with 284 additions and 6 deletions

View File

@@ -1,7 +1,7 @@
# Minabot
Minimal Bun + Hono backend and React Router client, initialized with Bun's
shadcn + Tailwind CSS v4 template.
Minimal Bun + Hono backend with Drizzle ORM and local SQLite, and a React Router
client initialized with Bun's shadcn + Tailwind CSS v4 template.
```sh
bun install
@@ -26,3 +26,26 @@ bun start
The build includes the backend and frontend in `dist/`. `bun start` serves that
production build. Client routes support direct loading and browser history.
## Database
The backend uses Drizzle ORM with Bun's built-in SQLite driver. The database is
created at `data/minabot.sqlite`, with WAL mode and foreign keys enabled. Database
files are ignored by Git. Development and production use the same file.
Optionally copy `.env.example` to `.env` and set `DATABASE_PATH` to another local
file. Relative paths are resolved from the project root by the package scripts.
Define tables in `src/db/schema.ts`, then generate and apply migrations:
```sh
bun run db:generate --name describe_change
bun run db:migrate
```
Commit the generated `drizzle/` files alongside schema changes. `bun dev` and
`bun start` apply pending migrations before starting the server. The initial
schema contains no application tables.
Import `db` from `src/db/index.ts` in backend code to query the database.
`GET /api/health` checks the database connection before returning success.