@bettercms-ai/db 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -0
- package/dist/index.d.ts +43602 -0
- package/dist/index.js +28445 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/entry-noindex.d.ts +21 -0
- package/dist/lib/entry-noindex.js +8 -0
- package/dist/lib/entry-noindex.js.map +1 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# `@bettercms-ai/db`
|
|
2
|
+
|
|
3
|
+
> Drizzle ORM schema package for BetterCMS — self-hosted Postgres with `postgres` driver.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package contains all database table definitions for the BetterCMS backend. It uses **Drizzle ORM** with the **`postgres`** driver for self-hosted Postgres connections.
|
|
8
|
+
|
|
9
|
+
## Schema
|
|
10
|
+
|
|
11
|
+
14 tables matching the PRD §9 Data Model:
|
|
12
|
+
|
|
13
|
+
| Table | Description |
|
|
14
|
+
|-------|-------------|
|
|
15
|
+
| `workspaces` | Top-level tenant container |
|
|
16
|
+
| `users` | BetterAuth-managed user accounts |
|
|
17
|
+
| `workspace_members` | User↔workspace junction with roles |
|
|
18
|
+
| `content_models` | Schema definitions for structured content |
|
|
19
|
+
| `content_entries` | Instances of content models |
|
|
20
|
+
| `pages` | CMS pages with JSONB block trees |
|
|
21
|
+
| `media_assets` | Cloudflare R2-stored media metadata |
|
|
22
|
+
| `forms` | Form definitions with webhook support |
|
|
23
|
+
| `form_submissions` | Visitor form submissions |
|
|
24
|
+
| `redirects` | URL redirect rules (301/302/307/308) |
|
|
25
|
+
| `api_keys` | Workspace-scoped delivery API keys |
|
|
26
|
+
| `plan_limits` | Plan tier resource quotas |
|
|
27
|
+
| `audit_logs` | Immutable event log (Phase 6) |
|
|
28
|
+
|
|
29
|
+
## Key Design Decisions
|
|
30
|
+
|
|
31
|
+
- **Text IDs** — all primary keys use `text` (nanoid) for consistency with BetterAuth
|
|
32
|
+
- **Workspace isolation** — every tenant-scoped table has a `workspace_id text()` FK
|
|
33
|
+
- **Soft deletes** — tables with `deleted_at timestamp()` for recoverable deletions
|
|
34
|
+
- **JSONB** — used for `block_json`, `fields`, `data`, and `event_data` columns
|
|
35
|
+
- **Indexes** — optimized for workspace-scoping, slug lookups, and status filters
|
|
36
|
+
- **`block_embedding`** — `text` column on `pages` for Phase 2 pgvector AI search
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { db, schema } from "@bettercms-ai/db";
|
|
42
|
+
|
|
43
|
+
// Query pages for a workspace
|
|
44
|
+
const pages = await db
|
|
45
|
+
.select()
|
|
46
|
+
.from(schema.pages)
|
|
47
|
+
.where(eq(schema.pages.workspaceId, workspaceId));
|
|
48
|
+
|
|
49
|
+
// Insert a new page
|
|
50
|
+
await db.insert(schema.pages).values({
|
|
51
|
+
id: nanoid(),
|
|
52
|
+
workspaceId,
|
|
53
|
+
title: "Hello World",
|
|
54
|
+
slug: "hello-world",
|
|
55
|
+
status: "draft",
|
|
56
|
+
blockJson: [],
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Scripts
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
bun run db:generate # Generate migrations (drizzle-kit generate)
|
|
64
|
+
bun run db:push # Push schema to Neon (drizzle-kit push)
|
|
65
|
+
bun run db:migrate # Run migrations (drizzle-kit migrate)
|
|
66
|
+
bun run db:studio # Open Drizzle Studio (drizzle-kit studio)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Environment
|
|
70
|
+
|
|
71
|
+
Requires `DATABASE_URL` in your environment:
|
|
72
|
+
|
|
73
|
+
```env
|
|
74
|
+
DATABASE_URL=postgresql://user:password@localhost:5432/bettercms
|
|
75
|
+
```
|