caspian-utils 0.1.11 → 0.1.12

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.
@@ -105,6 +105,7 @@ npx prisma migrate dev
105
105
 
106
106
  # If the change requires refreshed seed data:
107
107
  npx prisma generate
108
+ # Destructive-data warning: ask the user for explicit approval before running this.
108
109
  npx prisma db seed
109
110
 
110
111
  npx ppy generate
@@ -112,6 +113,8 @@ npx ppy generate
112
113
 
113
114
  Use when `prisma/schema.prisma` changes and you need migrations, seed flow, and the generated Python ORM layer to stay aligned.
114
115
 
116
+ `npx prisma db seed` is a delicate operation because the configured seed script may clean tables or replace existing rows before inserting seed data. Before running it, an AI agent must say the exact command it plans to run, warn that it can delete or overwrite database data, confirm the active datasource when practical, and wait for explicit user approval.
117
+
115
118
  ## 2. Script Guardrails
116
119
 
117
120
  - Before using an optional feature, confirm its flag in `caspian.config.json`.
@@ -179,12 +182,12 @@ In skip-prompt mode, the default feature values are:
179
182
 
180
183
  - `backendOnly: false`
181
184
  - `tailwindcss: false`
182
- - `typescript: false`
183
- - `mcp: false`
184
- - `prisma: false`
185
- - `websocket: false`
186
-
187
- If a project needs WebSockets after creation, set `websocket: true` in `caspian.config.json`, then run the project update workflow so framework-managed files and any scaffolded socket surfaces stay aligned before assuming `@app.websocket(...)` routes or `src/lib/websocket/**` exist.
185
+ - `typescript: false`
186
+ - `mcp: false`
187
+ - `prisma: false`
188
+ - `websocket: false`
189
+
190
+ If a project needs WebSockets after creation, set `websocket: true` in `caspian.config.json`, then run the project update workflow so framework-managed files and any scaffolded socket surfaces stay aligned before assuming `@app.websocket(...)` routes or `src/lib/websocket/**` exist.
188
191
 
189
192
  ### 4.2 Backend-only combinations
190
193
 
@@ -597,6 +600,7 @@ npx prisma migrate dev
597
600
 
598
601
  # Only when seed flow or prisma/seed.ts depends on the new schema:
599
602
  npx prisma generate
603
+ # Destructive-data warning: ask the user for explicit approval before running this.
600
604
  npx prisma db seed
601
605
 
602
606
  npx ppy generate
@@ -605,7 +609,7 @@ npx ppy generate
605
609
  Use this order:
606
610
 
607
611
  1. Run `npx prisma migrate dev` first so migrations and the development database stay aligned.
608
- 2. If `prisma/seed.ts` or seed data depends on the new schema, run `npx prisma generate` and then `npx prisma db seed`.
612
+ 2. If `prisma/seed.ts` or seed data depends on the new schema, run `npx prisma generate`, then request explicit user approval before running `npx prisma db seed` because the seed script may delete or overwrite database data.
609
613
  3. Run `npx ppy generate` last so the generated Python ORM layer matches the updated Prisma schema.
610
614
 
611
615
  Do not manually create or edit these generated files:
@@ -678,7 +682,7 @@ If an AI agent is deciding which command flow to use, apply these rules first.
678
682
  - Treat `--tailwindcss` and `--typescript` as frontend-oriented flags. They are not meaningful in normal backend-only scaffolds.
679
683
  - Treat starter kit defaults as a base layer that can be overridden by explicit flags.
680
684
  - Read `caspian.config.json` before running update commands.
681
- - When `prisma/schema.prisma` changes, run `npx prisma migrate dev` first, then any required seed refresh, then `npx ppy generate`.
685
+ - When `prisma/schema.prisma` changes, run `npx prisma migrate dev` first, then any required seed refresh, then `npx ppy generate`. Before running `npx prisma db seed`, warn the user that it can delete or overwrite data and wait for explicit approval.
682
686
  - Never hand-edit generated Python ORM files under `src/lib/prisma/` or `settings/prisma-schema.json`.
683
687
  - Read [database.md](./database.md) before generating Prisma schema, migration, seed, or ORM guidance.
684
688
  - Read [routing.md](./routing.md) before generating or modifying route folders under `src/app/`.
@@ -14,9 +14,9 @@ related:
14
14
 
15
15
  This page documents the Prisma workflow for Caspian projects where `caspian.config.json` enables Prisma.
16
16
 
17
- When a project enables Prisma, use `prisma/schema.prisma` for schema management, `prisma.config.ts` for Prisma config and seed wiring, and reuse an app-owned `src/lib/prisma/` package when the project includes one.
18
-
19
- High-priority rule: when `caspian.config.json` has `prisma: true`, Python-side database access must use the generated Prisma Python ORM. Route `page()` functions, route-owned `@rpc()` actions, auth handlers, upload flows, and shared helpers should import the generated client from `src/lib/prisma/**` instead of inventing direct driver calls, hand-written SQL wrappers, JSON manifests as active stores, app-specific HTTP fetches, or browser-side database fetches. For normal reads and writes, default to Prisma methods such as `find_many`, `find_unique`, `create`, `update`, `delete`, `delete_many`, aggregates, includes, and transactions. Use raw SQL only through Prisma as a narrow fallback when the generated ORM cannot express a query clearly, and treat that fallback as provider-specific code that may break when a project moves between SQLite, MySQL, and PostgreSQL.
17
+ When a project enables Prisma, use `prisma/schema.prisma` for schema management, `prisma.config.ts` for Prisma config and seed wiring, and reuse an app-owned `src/lib/prisma/` package when the project includes one.
18
+
19
+ High-priority rule: when `caspian.config.json` has `prisma: true`, Python-side database access must use the generated Prisma Python ORM. Route `page()` functions, route-owned `@rpc()` actions, auth handlers, upload flows, and shared helpers should import the generated client from `src/lib/prisma/**` instead of inventing direct driver calls, hand-written SQL wrappers, JSON manifests as active stores, app-specific HTTP fetches, or browser-side database fetches. For normal reads and writes, default to Prisma methods such as `find_many`, `find_unique`, `create`, `update`, `delete`, `delete_many`, aggregates, includes, and transactions. Use raw SQL only through Prisma as a narrow fallback when the generated ORM cannot express a query clearly, and treat that fallback as provider-specific code that may break when a project moves between SQLite, MySQL, and PostgreSQL.
20
20
 
21
21
  Treat `caspian.config.json` as the single source of truth for whether Prisma is enabled in a workspace. If `prisma` is false and the user wants Prisma, ask first, then update `caspian.config.json` and run `npx casp update project` before assuming Prisma-managed files exist.
22
22
 
@@ -27,11 +27,25 @@ The standard Prisma flow in Caspian is:
27
27
  1. Define models in `prisma/schema.prisma`.
28
28
  2. Configure `DATABASE_URL` in `.env`.
29
29
  3. Run `npx prisma migrate dev` after schema changes so the development database and migration history stay aligned.
30
- 4. If the change requires seed data, run `npx prisma generate` and then `npx prisma db seed`.
30
+ 4. If the change requires seed data, run `npx prisma generate`, then request explicit user approval before running `npx prisma db seed`.
31
31
  5. Run `npx ppy generate` so the Python ORM classes stay aligned with the updated schema.
32
32
  6. Reuse the shared Python database layer in `src/lib/prisma/` when Python route or RPC code needs database access, and never hand-edit generated ORM classes.
33
33
 
34
- Use this workflow instead of writing raw SQL first. For normal CRUD and relation work, stay on the generated Prisma API. Drop to raw SQL only through Prisma when a query cannot be expressed clearly with the generated client, and assume that raw SQL requires extra review for cross-database portability.
34
+ Use this workflow instead of writing raw SQL first. For normal CRUD and relation work, stay on the generated Prisma API. Drop to raw SQL only through Prisma when a query cannot be expressed clearly with the generated client, and assume that raw SQL requires extra review for cross-database portability.
35
+
36
+ ## Seed Command Safety
37
+
38
+ Treat `npx prisma db seed` as a destructive data operation, not as a routine regeneration command. A project's `prisma/seed.ts` may delete existing rows, reset lookup tables, replace users, or otherwise rewrite the current datasource before inserting seed data. If `DATABASE_URL` points at a shared, staging, or production database, running the seed command can delete production information.
39
+
40
+ Before any AI agent runs `npx prisma db seed`, it must:
41
+
42
+ 1. Read `prisma.config.ts` and `prisma/seed.ts` to understand what the seed command will execute.
43
+ 2. State the exact command it intends to run: `npx prisma db seed`.
44
+ 3. Warn the user clearly that the command can delete or overwrite database data.
45
+ 4. Confirm the active datasource or `DATABASE_URL` when practical, without exposing secrets.
46
+ 5. Wait for explicit user approval before executing the command.
47
+
48
+ Do not run `npx prisma db seed` merely because it appears in the standard workflow. Ask first, and only continue after the user has approved that specific seed operation.
35
49
 
36
50
  ## Environment Setup
37
51
 
@@ -49,7 +63,7 @@ Example for PostgreSQL in async-friendly production environments:
49
63
  DATABASE_URL="postgresql://user:password@localhost:5432/mydb"
50
64
  ```
51
65
 
52
- For most local development, SQLite is the simplest starting point. For production or higher concurrency workloads, prefer PostgreSQL or MySQL. Regardless of the starting provider, keep application queries on the Prisma ORM whenever possible so schema and query behavior stay easier to migrate across providers.
66
+ For most local development, SQLite is the simplest starting point. For production or higher concurrency workloads, prefer PostgreSQL or MySQL. Regardless of the starting provider, keep application queries on the Prisma ORM whenever possible so schema and query behavior stay easier to migrate across providers.
53
67
 
54
68
  ## Global Prisma Configuration
55
69
 
@@ -107,7 +121,7 @@ model Post {
107
121
  After changing the schema, use this order:
108
122
 
109
123
  1. Run `npx prisma migrate dev`.
110
- 2. If seed data or the seed script needs the new schema, run `npx prisma generate` and then `npx prisma db seed`.
124
+ 2. If seed data or the seed script needs the new schema, run `npx prisma generate`, then request explicit user approval before running `npx prisma db seed`.
111
125
  3. Run `npx ppy generate` to refresh the generated Python ORM classes.
112
126
 
113
127
  Do not hand-edit generated Prisma or Python ORM output. Treat `prisma/schema.prisma` as the source of truth and regenerate from it.
@@ -118,7 +132,7 @@ Use these commands for the normal Prisma lifecycle in Caspian:
118
132
 
119
133
  - `npx prisma migrate dev` creates and applies a development migration. This is the first command to run after changing `prisma/schema.prisma`.
120
134
  - `npx prisma generate` compiles `schema.prisma` into the generated Node Prisma client. Run it before `npx prisma db seed` when the updated seed flow depends on the new schema.
121
- - `npx prisma db seed` runs the configured seeding script.
135
+ - `npx prisma db seed` runs the configured seeding script. This may delete or overwrite existing database data; an AI agent must warn the user and receive explicit approval before executing it.
122
136
  - `npx ppy generate` regenerates the Python ORM classes used by the app. Use this after every schema change.
123
137
  - `npx prisma migrate deploy` applies pending migrations in deployment environments.
124
138
  - `npx prisma db push` syncs schema changes without creating a migration file, which is useful for prototyping.
@@ -126,7 +140,7 @@ Use these commands for the normal Prisma lifecycle in Caspian:
126
140
 
127
141
  Default rule:
128
142
 
129
- - When `prisma/schema.prisma` changes, use this order: `npx prisma migrate dev`; if seeding is involved, run `npx prisma generate` and `npx prisma db seed`; then run `npx ppy generate`.
143
+ - When `prisma/schema.prisma` changes, use this order: `npx prisma migrate dev`; if seeding is involved, run `npx prisma generate`, ask for explicit approval before `npx prisma db seed`, then run `npx ppy generate`.
130
144
  - Never hand-edit generated Prisma or Python ORM classes, and never replace `npx ppy generate` with a manual class update.
131
145
  - Use migrations for tracked application changes.
132
146
  - Use `db push` only when you intentionally want a faster, migration-free prototype loop.
@@ -159,7 +173,7 @@ If Python route or RPC code needs database access, import from `src.lib.prisma`
159
173
 
160
174
  ## Python Route Usage
161
175
 
162
- If the project ships an app-owned Python Prisma-style layer under `src/lib/prisma/`, treat it as async-first and reuse it from route and RPC code. In a Prisma-enabled project, this is the required data-access path for Python code.
176
+ If the project ships an app-owned Python Prisma-style layer under `src/lib/prisma/`, treat it as async-first and reuse it from route and RPC code. In a Prisma-enabled project, this is the required data-access path for Python code.
163
177
 
164
178
  Example:
165
179
 
@@ -180,7 +194,7 @@ Prisma calls fit naturally in:
180
194
  - `async def page()` for first-render data
181
195
  - `@rpc()` actions for browser-triggered reads and writes
182
196
 
183
- Keep route-specific Prisma I/O in that route's `page()` or `@rpc()` actions in `src/app/**/index.py`. The installed layout engine supports synchronous and async `layout()` results, but layout work should stay focused on shared subtree props or metadata. Move Prisma helpers into `src/lib/**` only when the same behavior is reused by multiple routes, features, or integrations.
197
+ Keep route-specific Prisma I/O in that route's `page()` or `@rpc()` actions in `src/app/**/index.py`. The installed layout engine supports synchronous and async `layout()` results, but layout work should stay focused on shared subtree props or metadata. Move Prisma helpers into `src/lib/**` only when the same behavior is reused by multiple routes, features, or integrations.
184
198
 
185
199
  See `fetch-data.md` for the recommended route-render versus RPC split.
186
200
 
@@ -318,39 +332,39 @@ async with prisma.transaction() as tx:
318
332
  )
319
333
  ```
320
334
 
321
- ### Raw SQL Fallback
322
-
323
- Use this escape hatch sparingly. Raw SQL is not the default query style in a Prisma-enabled Caspian project.
324
-
325
- Before using `query_raw()` or `execute_raw()`, confirm that the generated Prisma API cannot express the query clearly with normal methods such as `find_many`, `find_unique`, `create`, `update`, `delete`, `delete_many`, `aggregate`, relation `include`, or transactions.
326
-
327
- Important portability warning:
328
-
329
- - Raw SQL is provider-specific. Placeholder style, identifier quoting, JSON operators, case-sensitivity rules, date functions, and aggregate behavior can differ across SQLite, MySQL, and PostgreSQL.
330
- - A raw query that works in SQLite may fail after a move to PostgreSQL or MySQL even when the Prisma schema migrates cleanly.
331
- - If a project may switch providers, prefer Prisma ORM methods first and treat raw SQL as an exception that needs provider-aware review.
332
-
333
- ```python
334
- users = await prisma.user.find_many(
335
- where={
336
- "email": {"contains": "@gmail.com"},
337
- },
338
- )
339
- ```
340
-
341
- If raw SQL is still unavoidable, keep it tightly scoped, document why the ORM was insufficient, and verify it against the current datasource provider in `prisma/schema.prisma`.
335
+ ### Raw SQL Fallback
336
+
337
+ Use this escape hatch sparingly. Raw SQL is not the default query style in a Prisma-enabled Caspian project.
338
+
339
+ Before using `query_raw()` or `execute_raw()`, confirm that the generated Prisma API cannot express the query clearly with normal methods such as `find_many`, `find_unique`, `create`, `update`, `delete`, `delete_many`, `aggregate`, relation `include`, or transactions.
340
+
341
+ Important portability warning:
342
+
343
+ - Raw SQL is provider-specific. Placeholder style, identifier quoting, JSON operators, case-sensitivity rules, date functions, and aggregate behavior can differ across SQLite, MySQL, and PostgreSQL.
344
+ - A raw query that works in SQLite may fail after a move to PostgreSQL or MySQL even when the Prisma schema migrates cleanly.
345
+ - If a project may switch providers, prefer Prisma ORM methods first and treat raw SQL as an exception that needs provider-aware review.
346
+
347
+ ```python
348
+ users = await prisma.user.find_many(
349
+ where={
350
+ "email": {"contains": "@gmail.com"},
351
+ },
352
+ )
353
+ ```
354
+
355
+ If raw SQL is still unavoidable, keep it tightly scoped, document why the ORM was insufficient, and verify it against the current datasource provider in `prisma/schema.prisma`.
342
356
 
343
357
  ## Recommended Project Rules
344
358
 
345
359
  - Keep the schema in `prisma/schema.prisma` and follow the required regeneration order after changes: `npx prisma migrate dev`, optional seed flow, then `npx ppy generate`.
346
- - Reuse `src/lib/prisma/` for Python-side database access instead of creating a second bridge.
347
- - When Prisma is enabled, do not bypass the Prisma Python ORM with direct database drivers, custom fetch functions, JSON files as active stores, or browser-side database access.
360
+ - Reuse `src/lib/prisma/` for Python-side database access instead of creating a second bridge.
361
+ - When Prisma is enabled, do not bypass the Prisma Python ORM with direct database drivers, custom fetch functions, JSON files as active stores, or browser-side database access.
348
362
  - Never hand-edit generated Prisma or Python ORM classes.
349
363
  - Keep reusable database helpers in `src/lib/`, and keep route-specific orchestration in `src/app/`.
350
364
  - Use `await` with Prisma operations.
351
365
  - Convert Prisma objects to template-safe dictionaries when rendering HTML.
352
366
  - Validate incoming mutation data before calling `create`, `update`, or `delete` operations.
353
- - Prefer Prisma queries over raw SQL. If raw SQL is unavoidable, keep it provider-aware, narrowly scoped, and documented so future database-provider migrations do not silently break application behavior.
367
+ - Prefer Prisma queries over raw SQL. If raw SQL is unavoidable, keep it provider-aware, narrowly scoped, and documented so future database-provider migrations do not silently break application behavior.
354
368
 
355
369
  ## AI Retrieval Notes
356
370
 
@@ -359,13 +373,13 @@ If an AI agent is working on a Caspian app with Prisma enabled, apply these rule
359
373
  - Treat Prisma as the default ORM and persistence layer.
360
374
  - Read `prisma/schema.prisma` before proposing model, relation, or field changes.
361
375
  - When `prisma/schema.prisma` changes, run `npx prisma migrate dev` first.
362
- - If the schema change requires seed data, run `npx prisma generate` and then `npx prisma db seed`.
376
+ - If the schema change requires seed data, run `npx prisma generate`, then request explicit user approval before running `npx prisma db seed`.
363
377
  - Run `npx ppy generate` after schema changes to refresh the Python ORM classes.
364
378
  - Never hand-edit generated Prisma or Python ORM classes.
365
379
  - Read `prisma.config.ts` and `prisma/seed.ts` when you need the current project's Prisma tooling examples.
366
- - Reuse the existing `src/lib/prisma/` package when the Python app needs database access.
367
- - Treat use of the Prisma Python ORM as mandatory for Python-side database reads and writes in Prisma-enabled projects.
380
+ - Reuse the existing `src/lib/prisma/` package when the Python app needs database access.
381
+ - Treat use of the Prisma Python ORM as mandatory for Python-side database reads and writes in Prisma-enabled projects.
368
382
  - For file managers and uploads, persist metadata in Prisma and keep blob storage separate. See [file-uploads.md](./file-uploads.md).
369
383
  - Put reusable database helpers in `src/lib/`; keep route and RPC orchestration in `src/app/`.
370
- - Use `async def page()` for route-specific first-render reads. Use `layout()` only for shared subtree props or metadata, and use `@rpc()` plus `pp.rpc()` for browser-triggered reads and writes.
384
+ - Use `async def page()` for route-specific first-render reads. Use `layout()` only for shared subtree props or metadata, and use `@rpc()` plus `pp.rpc()` for browser-triggered reads and writes.
371
385
  - Check `fetch-data.md` for route versus RPC guidance and `validation.md` before writing public mutations.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "caspian-utils",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "Caspian tooling",
5
5
  "main": "index.js",
6
6
  "scripts": {