supatool 0.3.6 → 0.4.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 CHANGED
@@ -1,330 +1,97 @@
1
1
  # Supatool
2
2
 
3
- A CLI tool that automatically generates TypeScript CRUD code from Supabase type definitions.
3
+ CLI for Supabase: **extract** schema to files with **llms.txt** for LLMs, and **seed** export as AI-friendly JSON. Deploy and CRUD (deprecated) also available.
4
4
 
5
5
  ## Features
6
- - Extract and categorize all database objects (tables, views, RLS, functions, triggers) from Supabase
7
- - Generate TypeScript CRUD functions from Supabase types or model YAML
8
- - Output human-readable and AI-friendly schema/index files
9
- - Flexible environment/configuration and batch processing
10
- - Simple CLI with help and documentation
11
6
 
12
- > For all new features and version history, see [CHANGELOG.md](./CHANGELOG.md).
7
+ - **Extract** Tables, views, RLS, functions, triggers from DB into files. One file per table (DDL + RLS + triggers). Multi-schema: `--schema public,agent` → `schemas/public/`, `schemas/agent/`.
8
+ - **llms.txt** – Catalog with OBJECTS, RELATIONS, RPC_TABLES, ALL_SCHEMAS. README in output links to it.
9
+ - **Seed** – Export table data to JSON; llms.txt index in `supabase/seeds/`.
10
+ - **Deploy** – Push local schema to remote (`supatool deploy --dry-run`).
11
+ - CRUD code gen is **deprecated** (`supatool crud`, `gen:crud`); prefer writing code with an LLM.
12
+
13
+ See [CHANGELOG.md](./CHANGELOG.md) for version history.
13
14
 
14
15
  ## Install
15
16
 
16
- ```
17
+ ```bash
17
18
  npm install -g supatool
18
- # or
19
- yarn global add supatool
20
- # or
21
- pnpm add -g supatool
19
+ # or: yarn global add supatool | pnpm add -g supatool
22
20
  ```
23
21
 
24
- ## Usage
22
+ ## Extract
25
23
 
26
- ### Extract Database Schema
27
-
28
- Extract and categorize all database objects from your Supabase project:
24
+ Set connection (e.g. in `.env.local`):
29
25
 
30
26
  ```bash
31
- # Set connection string in environment (recommended)
32
27
  echo "SUPABASE_CONNECTION_STRING=postgresql://..." >> .env.local
33
-
34
- # Extract all database objects with AI-friendly index
35
- supatool extract --all -o supabase/schemas
36
-
37
- # Extract only tables and views
38
- supatool extract -o supabase/schemas
39
-
40
- # Extract specific tables with pattern
41
- supatool extract -t "user_*" -o supabase/schemas
42
-
43
- # Extract from specific schemas (comma-separated)
44
- supatool extract --all --schema public,auth,extensions -o supabase/schemas
45
-
46
- # Alternative: specify connection directly
47
- supatool extract --all -c "postgresql://..." -o supabase/schemas
48
- ```
49
-
50
- **Output structure:**
51
- ```
52
- supabase/schemas/
53
- ├── index.md # Human-readable index with comments
54
- ├── llms.txt # AI-friendly structured data with comments
55
- ├── tables/ # Table definitions with comments
56
- ├── views/ # View definitions with comments
57
- ├── rls/ # RLS policies
58
- └── rpc/ # Functions & triggers
59
28
  ```
60
29
 
61
- ### Generate CRUD Code
62
-
63
- Generate TypeScript CRUD functions from Supabase types:
30
+ Extract all objects:
64
31
 
65
32
  ```bash
66
- # Generate from Supabase type definitions
67
- supatool crud
68
-
69
- # Generate from schema SQL files
70
- supatool gen:schema-crud --include-views --react-query
71
-
72
- # Generate from model YAML
73
- supatool gen:crud model.yaml
74
- ```
75
-
76
- **Output:** `src/integrations/supabase/crud-autogen/`
77
-
78
- ### Environment Configuration
79
-
80
- For security and convenience, set your connection string in environment variables:
81
-
82
- ```bash
83
- # Create .env.local file with your connection details
84
- cat > .env.local << EOF
85
- SUPABASE_CONNECTION_STRING=postgresql://user:password@host:port/database
86
- # Alternative: use DATABASE_URL
87
- DATABASE_URL=postgresql://user:password@host:port/database
88
- EOF
89
-
90
- # Now you can run commands without -c flag
91
33
  supatool extract --all -o supabase/schemas
34
+ # Optional: --schema public,agent | -t "user_*" | -c "postgresql://..."
35
+ # With --force: clears output dir then writes (no orphan files).
92
36
  ```
93
37
 
94
- **Supported environment variables:**
95
- - `SUPABASE_CONNECTION_STRING` (preferred)
96
- - `DATABASE_URL` (fallback)
97
- - `SUPATOOL_MAX_CONCURRENT` (max concurrent table processing, default: 20, max: 50)
98
-
99
- ### Additional Commands
100
-
101
- ```bash
102
- # Show help for all commands
103
- supatool help
104
-
105
- # Specify custom input/output paths
106
- supatool crud -i path/to/types -o path/to/output
107
- ```
108
-
109
- ## Database Comments
110
-
111
- Supatool automatically extracts and includes PostgreSQL comments in all generated files. Comments enhance documentation and AI understanding of your schema.
112
-
113
- - Table, view, function, and type comments are included in generated SQL and documentation.
114
- - AI-friendly index files (llms.txt) and Markdown index (index.md) include comments for better context.
115
-
116
- ## VSCode/Cursor Integration
117
-
118
- Add these tasks to `.vscode/tasks.json` for quick access:
119
-
120
- > **Note:** Restart VSCode/Cursor after installing supatool to ensure the command is recognized.
121
-
122
- ```json
123
- {
124
- "version": "2.0.0",
125
- "tasks": [
126
- {
127
- "label": "Extract Schema and Generate CRUD",
128
- "type": "shell",
129
- "command": "supatool extract --all -o supabase/schemas && supatool gen:schema-crud --react-query",
130
- "group": "build",
131
- "dependsOn": "setup-env"
132
- },
133
- {
134
- "label": "setup-env",
135
- "type": "shell",
136
- "command": "echo 'Ensure SUPABASE_CONNECTION_STRING is set in .env.local'",
137
- "group": "build"
138
- },
139
- {
140
- "label": "Generate Types and CRUD (Legacy)",
141
- "type": "shell",
142
- "command": "mkdir -p shared && npx supabase gen types typescript --project-id ${input:projectId} --schema public > shared/types.ts && supatool crud --force",
143
- "group": "build"
144
- }
145
- ],
146
- "inputs": [
147
- {
148
- "id": "projectId",
149
- "description": "Supabase project ID",
150
- "default": "your_project_id"
151
- }
152
- ]
153
- }
154
- ```
155
-
156
- ## Example: How to use generated CRUD code in your apps
157
-
158
- CRUD utility files for the `apps` table will be generated in `src/integrations/supabase/crud-autogen/` by default.
159
-
160
- You can import and use these functions in your application as follows:
161
-
162
- ```ts
163
- // Example: Using CRUD functions for the apps table (v0.3.0+)
164
- import {
165
- selectAppsRowsWithFilters,
166
- selectAppsSingleRowWithFilters,
167
- selectAppsRowById,
168
- insertAppsRow,
169
- updateAppsRow,
170
- deleteAppsRow,
171
- } from 'src/integrations/supabase/crud-autogen/apps';
172
-
173
- // Select multiple rows with filters (NEW: destructuring parameters)
174
- const apps = await selectAppsRowsWithFilters({ filters: { status: 'active' } });
175
-
176
- // Select a single row with filters
177
- const app = await selectAppsSingleRowWithFilters({ filters: { id: 'your-app-id' } });
38
+ **Output:**
178
39
 
179
- // Select by ID (NEW: destructuring parameters)
180
- const appById = await selectAppsRowById({ id: 'your-app-id' });
181
-
182
- // Insert new row (NEW: destructuring parameters)
183
- const newApp = await insertAppsRow({ data: { name: 'New App', status: 'active' } });
184
-
185
- // Update row (NEW: destructuring parameters)
186
- const updatedApp = await updateAppsRow({
187
- id: 'your-app-id',
188
- data: { name: 'Updated Name' }
189
- });
190
-
191
- // Delete row (NEW: destructuring parameters)
192
- const success = await deleteAppsRow({ id: 'your-app-id' });
193
40
  ```
194
-
195
- - All functions are async and return the corresponding row type.
196
- - You can use filter objects for flexible queries.
197
- - See the generated file for each table in `src/integrations/supabase/crud-autogen/` for details.
198
-
199
- ## Limitations
200
-
201
- Currently, the generated code only supports tables where the primary key column is named `id`.
202
- If your table's primary key is not named `id`, the `selectById`, `update`, and `delete` functions will not be generated for that table.
203
-
204
- ## Repository
205
-
206
- For more details, see the project on GitHub: [https://github.com/idea-garage/supatool](https://github.com/idea-garage/supatool)
207
-
208
- ## Acknowledgements
209
-
210
- This project is inspired by and made possible thanks to the amazing work of [Supabase](https://supabase.com/).
211
-
212
- ## Complete Workflow Examples
213
-
214
- ### Database-First Development
215
-
216
- Extract your existing database schema and generate CRUD code using [Supabase's declarative schema workflow](https://supabase.com/docs/guides/local-development/declarative-database-schemas):
217
-
218
- ```bash
219
- # 1. Set connection string in .env.local
220
- echo "SUPABASE_CONNECTION_STRING=postgresql://..." >> .env.local
221
-
222
- # 2. Extract all database objects to supabase/schemas (declarative schema format)
223
- supatool extract --all -o supabase/schemas
224
-
225
- # 3. Generate migrations from declarative schema
226
- supabase db diff -f initial_schema
227
-
228
- # 4. Generate TypeScript types with Supabase CLI
229
- npx supabase gen types typescript --local > src/types/database.ts
230
-
231
- # 5. Generate CRUD functions with React Query support
232
- supatool gen:schema-crud --include-views --react-query
41
+ supabase/schemas/
42
+ ├── README.md # Points to llms.txt
43
+ ├── llms.txt # OBJECTS, RELATIONS, RPC_TABLES, ALL_SCHEMAS (read this first for AI)
44
+ ├── schema_index.json # Same as llms.txt, for agents that parse JSON
45
+ ├── schema_summary.md # One-file overview: tables, relations, RPCs
46
+ ├── tables/
47
+ ├── views/
48
+ ├── rpc/
49
+ ├── cron/
50
+ └── types/
233
51
  ```
234
52
 
235
- ### Model-First Development
236
-
237
- Start from YAML model definitions:
238
-
239
- ```bash
240
- # 1. Create model definition
241
- supatool create model.yaml
53
+ Multi-schema: `schemas/public/`, `schemas/agent/`, etc., each with tables/, views/, rpc/.
242
54
 
243
- # 2. Generate everything from model
244
- supatool gen:all model.yaml
245
- ```
55
+ **Env:** `SUPABASE_CONNECTION_STRING` or `DATABASE_URL`; optional `SUPATOOL_MAX_CONCURRENT` (default 20).
246
56
 
247
- ### Extract Command Options
57
+ ## Seed
248
58
 
249
- Extract database objects in Supabase declarative schema format:
59
+ Export selected tables as JSON for AI/reference:
250
60
 
251
61
  ```bash
252
- # Recommended: Set connection in .env.local first
253
- echo "SUPABASE_CONNECTION_STRING=postgresql://..." >> .env.local
254
-
255
- # Extract all database objects to categorized directories (recommended)
256
- supatool extract --all -o supabase/schemas
257
- # Output: supabase/schemas/{index.md,tables/,views/,rls/,rpc/}
258
- # Compatible with: supabase db diff
259
-
260
- # Extract only tables and views
261
- supatool extract -o supabase/schemas
262
- # Output: supabase/schemas/{index.md,tables/,views/}
263
-
264
- # Extract to single directory (for simple projects)
265
- supatool extract --no-separate -o supabase/schemas
266
- # Output: supabase/schemas/{index.md,*.sql}
267
-
268
- # Extract with pattern matching
269
- supatool extract -t "user_*" -o ./user-tables
270
-
271
- # Extract from specific schemas (default: public)
272
- supatool extract --all --schema public,auth,extensions -o supabase/schemas
273
-
274
- # Alternative: specify connection directly
275
- supatool extract --all -c "postgresql://..." -o supabase/schemas
62
+ supatool seed --tables tables.yaml --connection "postgresql://..."
276
63
  ```
277
64
 
278
- ## Seed Command (v0.3.5+)
279
-
280
- Export selected table data from your remote Supabase DB as AI-friendly seed JSON files.
65
+ `tables.yaml`:
281
66
 
282
- ### Usage
283
-
284
- ```
285
- supatool seed --tables tables.yaml --connection <CONNECTION_STRING>
67
+ ```yaml
68
+ tables:
69
+ - users
70
+ - public.orders
286
71
  ```
287
72
 
288
- - `tables.yaml` example:
289
- ```yaml
290
- tables:
291
- - users
292
- - public.orders
293
- ```
294
73
  - Output: `supabase/seeds/<timestamp>_supatool/{table}_seed.json`
295
- - Each file contains a snapshot of the remote DB table at the time of export.
74
+ - `llms.txt` is written in `supabase/seeds/` listing files and row counts.
296
75
 
297
- ### Example output (users_seed.json)
298
- ```json
299
- {
300
- "table": "public.users",
301
- "fetched_at": "2024-07-05T11:16:00Z",
302
- "fetched_by": "supatool v0.3.5",
303
- "note": "This data is a snapshot of the remote DB at the above time. For AI coding reference. You can update it by running the update command again.",
304
- "rows": [
305
- { "id": 1, "name": "Taro Yamada", "email": "taro@example.com" },
306
- { "id": 2, "name": "Hanako Suzuki", "email": "hanako@example.com" }
307
- ]
308
- }
309
- ```
76
+ Do not include sensitive data in seed files.
310
77
 
311
- > **Warning:** Do not include sensitive or personal data in seed files. Handle all exported data with care.
78
+ ## For AI / coding agents (Claude CLI, Cursor, etc.)
312
79
 
313
- ### llms.txt (AI seed data index)
80
+ - **Entry point:** Read `supabase/schemas/llms.txt` first. It lists all objects, relations, RPC→tables, and schemas.
81
+ - **Then** open only the files you need (paths under OBJECTS). Use RELATIONS for joins; RPC_TABLES to see which RPCs touch which tables.
82
+ - **Optional:** `schema_index.json` (same data as llms.txt) and `schema_summary.md` (one-file overview) are written when you run `supatool extract`.
83
+ - **Seeds:** `supabase/seeds/llms.txt` lists seed JSON files; it references the schema catalog at `../schemas/llms.txt` when present.
314
84
 
315
- After exporting, a file named `llms.txt` is automatically generated (and overwritten) in the `supabase/seeds/` directory. This file lists all seed JSON files in the latest timestamped folder, with table name, fetch time, and row count for AI reference.
85
+ ## Other commands
316
86
 
317
- - Note: `llms.txt` is not generated inside each timestamped subfolder, only in `supabase/seeds/`.
87
+ - `supatool help` List commands
88
+ - `supatool deploy --dry-run` – Preview deploy
89
+ - CRUD: `supatool crud`, `gen:crud` (deprecated)
318
90
 
319
- #### Example llms.txt
320
- ```
321
- # AI seed data index (generated by supatool)
322
- # fetched_at: 2024-07-05T11:16:00Z
323
- # folder: 20240705_1116_supatool
324
- public.users: users_seed.json (2 rows) # User account table
325
- public.orders: orders_seed.json (5 rows)
326
- ```
91
+ ## Repository
92
+
93
+ [https://github.com/idea-garage/supatool](https://github.com/idea-garage/supatool) · [npm](https://www.npmjs.com/package/supatool)
327
94
 
328
- ## More Information
95
+ ---
329
96
 
330
- For full version history and detailed changes, see [CHANGELOG.md](./CHANGELOG.md).
97
+ Acknowledgements: Development would not be this convenient without [Supabase](https://supabase.com/). Thanks to the team and the platform.
@@ -12,14 +12,15 @@ Usage:
12
12
  Commands:
13
13
  extract Extract database objects from Supabase
14
14
  gen:types Generate TypeScript types from model YAML
15
- gen:crud Generate CRUD TypeScript code from model YAML
15
+ gen:crud Generate CRUD TypeScript code from model YAML [deprecated - prefer writing code with LLM]
16
16
  gen:docs Generate Markdown documentation from model YAML
17
17
  gen:sql Generate SQL (tables, relations, RLS/security) from model YAML
18
18
  gen:rls Generate RLS/security SQL from model YAML
19
19
  gen:all Generate all outputs from model YAML
20
20
  create Generate a template model YAML
21
- crud Generate CRUD code from Supabase type definitions
22
- sync Sync local and remote schemas
21
+ crud Generate CRUD code from Supabase type definitions [deprecated - prefer writing code with LLM]
22
+ deploy Deploy local schema changes to remote (recommended)
23
+ sync Sync local and remote schemas [deprecated - use deploy]
23
24
  seed Export selected table data as AI-friendly seed JSON
24
25
  config:init Generate configuration template
25
26
  help Show help