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.
52 lines
1.6 KiB
Markdown
52 lines
1.6 KiB
Markdown
# Minabot
|
|
|
|
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
|
|
bun dev
|
|
```
|
|
|
|
Open http://127.0.0.1:3000. Set `PORT` to use a different port.
|
|
|
|
- Client pages: `/`, `/about`, `/settings`.
|
|
- Hono endpoint: `GET /api/health`.
|
|
- Unknown API routes return JSON with a 404 status.
|
|
|
|
Pages contain only a heading and native navigation buttons. Tailwind utilities
|
|
and shadcn configuration are available; Tailwind Preflight is omitted to preserve
|
|
native browser styling.
|
|
|
|
```sh
|
|
bun run typecheck
|
|
bun run build
|
|
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.
|