@take-out/cli 0.0.40 → 0.0.42

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/docs/database.md DELETED
@@ -1,203 +0,0 @@
1
- ---
2
- name: database
3
- description: Database guide for PostgreSQL, Drizzle ORM, and Zero sync. INVOKE WHEN: Drizzle, migrations, schema changes, ALTER TABLE, SQL queries, getDb, getDBClient, queryDb, connection pooling, Aurora, pgvector, vector search.
4
- ---
5
-
6
- # Database
7
-
8
- This guide covers the database architecture, tools, and patterns used in this
9
- codebase.
10
-
11
- ## Overview
12
-
13
- The application uses PostgreSQL as its primary database with multiple access
14
- patterns and tools:
15
-
16
- PostgreSQL - primary database (locally via Docker, production via AWS Aurora
17
- Serverless v2) Drizzle ORM - type-safe ORM for schema management pgvector -
18
- vector database extension for semantic search Zero - real-time sync system with
19
- its own database requirements pg - direct PostgreSQL client for custom queries
20
-
21
- ## Local Development
22
-
23
- ### Database GUI - TablePlus
24
-
25
- TablePlus is the recommended database GUI for macOS. It provides a clean, native
26
- macOS interface, support for multiple database types, query editor with syntax
27
- highlighting, import/export capabilities, and SSH tunnel support for production
28
- databases.
29
-
30
- To connect to your local development database:
31
-
32
- Open TablePlus, create a new PostgreSQL connection, and use the connection
33
- string from `ZERO_UPSTREAM_DB` environment variable. Default local connection:
34
- `postgresql://user:password@127.0.0.1:5433/postgres`
35
-
36
- ### Command Line Access
37
-
38
- ```bash
39
- bun db:psql:dev
40
- QUERY="SELECT * FROM users LIMIT 5" bun db:psql:dev
41
- bun db:psql:dev -c "SELECT COUNT(*) FROM messages"
42
- ```
43
-
44
- ### Database Migrations
45
-
46
- ```bash
47
- bun db:migrate:add my-migration-name
48
- ```
49
-
50
- ## Query Patterns
51
-
52
- The codebase uses multiple query patterns depending on the use case.
53
-
54
- ### Drizzle ORM via getDb()
55
-
56
- Standard ORM queries for type-safe database operations:
57
-
58
- ```typescript
59
- import { getDb } from '~/database'
60
- import { users } from '~/database/schema-public'
61
-
62
- const db = getDb()
63
- const allUsers = await db.select().from(users)
64
- ```
65
-
66
- Location: src/database/index.ts:28
67
-
68
- ### Direct SQL with Template Literals
69
-
70
- For complex queries using the sql helper:
71
-
72
- ```typescript
73
- import { sql } from '~/database/sql'
74
-
75
- const result = await sql`
76
- SELECT * FROM users
77
- WHERE created_at > ${date}
78
- ORDER BY created_at DESC
79
- `
80
- ```
81
-
82
- Location: src/database/sql.ts:10
83
-
84
- ### Raw pg Client via getDBClient()
85
-
86
- For connection pooling and advanced PostgreSQL features:
87
-
88
- ```typescript
89
- import { getDBClient, queryDb } from '~/database/helpers'
90
-
91
- const client = await getDBClient()
92
- try {
93
- const result = await client.query('SELECT * FROM users')
94
- } finally {
95
- client.release()
96
- }
97
-
98
- const result = await queryDb('SELECT * FROM users WHERE id = $1', [userId])
99
- ```
100
-
101
- Location: src/database/getDBClient.ts:36
102
-
103
- ## Production Infrastructure (AWS Aurora)
104
-
105
- The production database runs on AWS Aurora Serverless v2 with PostgreSQL 16.6.
106
- Configuration defined in sst.config.ts.
107
-
108
- ### Connection Management
109
-
110
- The application implements sophisticated connection pooling to handle Aurora's
111
- connection limits:
112
-
113
- Connection pool with retry logic (src/database/getDBClient.ts:36), automatic
114
- connection limit monitoring, pool recycling when approaching limits,
115
- configurable timeouts and retry strategies.
116
-
117
- ## Migrations
118
-
119
- We use Drizzle only for schema migrations, but we often go outside of it for our
120
- own migration system which is designed to be very simple and builds so it runs
121
- locally and on AWS Lambda, when deploying to production.
122
-
123
- ### Migration Workflow
124
-
125
- For Drizzle schame changes in schema-public or schema-private, you just change
126
- the file and run `bun migrate:build`.
127
-
128
- If you're developing locally you can skip this and build and run migrations at
129
- the same time using `bun migrate`.
130
-
131
- ### Custom migrations
132
-
133
- ```bash
134
- bun db:migrate:add update-user-stats
135
- bun migrate
136
- bun migrate:production
137
- ```
138
-
139
- ### Custom Migration Example
140
-
141
- Location: src/database/scripts/migration-add.ts:37
142
-
143
- ```typescript
144
- import type { PoolClient } from 'pg'
145
-
146
- export async function up(client: PoolClient) {
147
- await client.query(`
148
- ALTER TABLE users
149
- ADD COLUMN last_seen TIMESTAMP
150
- `)
151
- }
152
- ```
153
-
154
- We don't do down migrations.
155
-
156
- ### Generated Columns in PostgreSQL
157
-
158
- When creating generated columns:
159
-
160
- Correct syntax for adding generated columns:
161
-
162
- ```sql
163
- ALTER TABLE "table_name"
164
- ADD COLUMN "column_name" data_type
165
- GENERATED ALWAYS AS (expression) STORED;
166
- ```
167
-
168
- Modifying existing columns to be generated: first drop the existing column, then
169
- add it back as generated. Cannot directly convert a regular column to generated.
170
-
171
- In Drizzle schema (src/database/schema-public.ts):
172
-
173
- ```typescript
174
- columnName: t.integer().generatedAlwaysAs(sql`expression`)
175
- ```
176
-
177
- ## Zero Database Requirements
178
-
179
- Zero requires specific database configuration:
180
-
181
- Three separate databases: main, CVR, and change tracking. Logical replication
182
- enabled. Connection strings configured via environment: ZERO_UPSTREAM_DB (main
183
- database), ZERO_CVR_DB (client view records), ZERO_CHANGE_DB (change tracking).
184
-
185
- ## Best Practices
186
-
187
- Connection Management: always release clients when using getDBClient(), use
188
- queryDb() helper for one-off queries, monitor connection pool usage in
189
- production.
190
-
191
- Migrations: test migrations locally before production, use transactions for data
192
- migrations.
193
-
194
- Query Performance: use indexes for frequently queried columns, monitor slow
195
- queries via Aurora logs, use EXPLAIN ANALYZE for query optimization.
196
-
197
- Security: never log sensitive data, use parameterized queries to prevent SQL
198
- injection, keep connection strings in environment variables.
199
-
200
- ## Integration Testing
201
-
202
- For information on database state management during integration testing, see the
203
- Integration Testing Guide (./testing-integration.md).
package/docs/docs.md DELETED
@@ -1,8 +0,0 @@
1
- ---
2
- name: docs
3
- description: Docs/documentation, writing english, JSDoc code comments, markdown, md, mdx, english
4
- ---
5
-
6
- # Writing documentation
7
-
8
- When writing markdown/docs, JSDoc, or other natural english, we prefer the keep things simple, avoid writing too many lists, avoid bolding things too much, avoid emojis. In general avoid over-use of tables unless it's a pattern found in similar docs elsewhere or truly essential to list out a table-like structure.