@prisma-next/cli 0.1.0-pr.72.1 → 0.2.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 +51 -68
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -102,7 +102,7 @@ prisma-next db verify [--db <url>] [--config <path>] [--json] [-v] [-q] [--times
|
|
|
102
102
|
```
|
|
103
103
|
|
|
104
104
|
Options:
|
|
105
|
-
- `--db <url>`: Database connection string (optional
|
|
105
|
+
- `--db <url>`: Database connection string (optional, falls back to `config.db.url` or `DATABASE_URL` environment variable)
|
|
106
106
|
- `--config <path>`: Optional. Path to `prisma-next.config.ts` (defaults to `./prisma-next.config.ts` if present)
|
|
107
107
|
- `--json`: Output as JSON object
|
|
108
108
|
- `-q, --quiet`: Quiet mode (errors only)
|
|
@@ -130,8 +130,6 @@ prisma-next db verify -v --timestamps
|
|
|
130
130
|
|
|
131
131
|
The `db verify` command requires a `driver` in the config to connect to the database:
|
|
132
132
|
|
|
133
|
-
If your emitted `contract.json` declares `extensionPacks`, your config must include matching descriptors in `extensions` (by `id`). The CLI validates this wiring before running the command.
|
|
134
|
-
|
|
135
133
|
```typescript
|
|
136
134
|
import { defineConfig } from '@prisma-next/cli/config-types';
|
|
137
135
|
import postgresAdapter from '@prisma-next/adapter-postgres/control';
|
|
@@ -258,7 +256,7 @@ prisma-next db introspect [--db <url>] [--config <path>] [--json] [-v] [-q] [--t
|
|
|
258
256
|
```
|
|
259
257
|
|
|
260
258
|
Options:
|
|
261
|
-
- `--db <url>`: Database connection string (optional
|
|
259
|
+
- `--db <url>`: Database connection string (optional, falls back to `config.db.url` or `DATABASE_URL` environment variable)
|
|
262
260
|
- `--config <path>`: Optional. Path to `prisma-next.config.ts` (defaults to `./prisma-next.config.ts` if present)
|
|
263
261
|
- `--json`: Output as JSON object
|
|
264
262
|
- `-q, --quiet`: Quiet mode (errors only)
|
|
@@ -375,7 +373,7 @@ sql schema (tables: 2)
|
|
|
375
373
|
|
|
376
374
|
**Error Codes:**
|
|
377
375
|
- `PN-CLI-4010`: Missing driver in config — provide a driver descriptor
|
|
378
|
-
- `PN-CLI-
|
|
376
|
+
- `PN-CLI-4011`: Missing database URL — provide `--db` flag or `config.db.url` or `DATABASE_URL` environment variable
|
|
379
377
|
|
|
380
378
|
**Family Requirements:**
|
|
381
379
|
|
|
@@ -409,7 +407,7 @@ prisma-next db sign [--db <url>] [--config <path>] [--json] [-v] [-q] [--timesta
|
|
|
409
407
|
```
|
|
410
408
|
|
|
411
409
|
Options:
|
|
412
|
-
- `--db <url>`: Database connection string (optional
|
|
410
|
+
- `--db <url>`: Database connection string (optional, falls back to `config.db.url` or `DATABASE_URL` environment variable)
|
|
413
411
|
- `--config <path>`: Optional. Path to `prisma-next.config.ts` (defaults to `./prisma-next.config.ts` if present)
|
|
414
412
|
- `--json`: Output as JSON object
|
|
415
413
|
- `-q, --quiet`: Quiet mode (errors only)
|
|
@@ -572,7 +570,7 @@ For updated markers:
|
|
|
572
570
|
|
|
573
571
|
**Error Codes:**
|
|
574
572
|
- `PN-CLI-4010`: Missing driver in config — provide a driver descriptor
|
|
575
|
-
- `PN-CLI-
|
|
573
|
+
- `PN-CLI-4011`: Missing database URL — provide `--db` flag or `config.db.url` or `DATABASE_URL` environment variable
|
|
576
574
|
- Exit code 1: Schema verification failed — database schema does not match contract (marker is not written)
|
|
577
575
|
|
|
578
576
|
**Relationship to Other Commands:**
|
|
@@ -611,7 +609,7 @@ The SQL family provides this via `@prisma-next/family-sql/control`. The `sign()`
|
|
|
611
609
|
|
|
612
610
|
### `prisma-next db init`
|
|
613
611
|
|
|
614
|
-
Initialize a database schema from the contract. This command
|
|
612
|
+
Initialize a database schema from the contract. This command generates a migration plan to bring an empty database in sync with the contract and executes it.
|
|
615
613
|
|
|
616
614
|
**Command:**
|
|
617
615
|
```bash
|
|
@@ -619,10 +617,10 @@ prisma-next db init [--db <url>] [--config <path>] [--plan] [--json] [-v] [-q] [
|
|
|
619
617
|
```
|
|
620
618
|
|
|
621
619
|
Options:
|
|
622
|
-
- `--db <url>`: Database connection string (optional
|
|
620
|
+
- `--db <url>`: Database connection string (optional, falls back to `config.db.url` or `DATABASE_URL` environment variable)
|
|
623
621
|
- `--config <path>`: Optional. Path to `prisma-next.config.ts` (defaults to `./prisma-next.config.ts` if present)
|
|
624
622
|
- `--plan`: Only show the migration plan, do not apply it
|
|
625
|
-
- `--json
|
|
623
|
+
- `--json`: Output as JSON object
|
|
626
624
|
- `-q, --quiet`: Quiet mode (errors only)
|
|
627
625
|
- `-v, --verbose`: Verbose output (debug info, timings)
|
|
628
626
|
- `-vv, --trace`: Trace output (deep internals, stack traces)
|
|
@@ -648,8 +646,6 @@ prisma-next db init --json
|
|
|
648
646
|
|
|
649
647
|
The `db init` command requires a `driver` in the config to connect to the database:
|
|
650
648
|
|
|
651
|
-
If your emitted `contract.json` declares `extensionPacks`, your config must include matching descriptors in `extensions` (by `id`). The CLI validates this wiring before running the command.
|
|
652
|
-
|
|
653
649
|
```typescript
|
|
654
650
|
import { defineConfig } from '@prisma-next/cli/config-types';
|
|
655
651
|
import postgresAdapter from '@prisma-next/adapter-postgres/control';
|
|
@@ -681,54 +677,49 @@ export default defineConfig({
|
|
|
681
677
|
2. **Connect to Database**: Uses `config.driver.create(url)` to create a driver
|
|
682
678
|
3. **Create Family Instance**: Calls `config.family.create()` with target, adapter, driver, and extensions
|
|
683
679
|
4. **Introspect Schema**: Calls `familyInstance.introspect()` to get the current database schema IR
|
|
684
|
-
5. **
|
|
685
|
-
|
|
686
|
-
- `contract.target` matches `config.target.targetId`
|
|
687
|
-
- `contract.extensionPacks` (if present) are provided by `config.extensions` (matched by descriptor `id`)
|
|
688
|
-
6. **Create Planner/Runner**: Uses `config.target.migrations.createPlanner()` and `config.target.migrations.createRunner()`
|
|
689
|
-
7. **Plan Migration**: Calls `planner.plan()` with the contract IR, schema IR, additive-only policy, and `frameworkComponents` (the active target/adapter/extension descriptors)
|
|
680
|
+
5. **Create Planner/Runner**: Asks the target to construct a `MigrationPlanner` and `MigrationRunner`
|
|
681
|
+
6. **Plan Migration**: Calls `planner.plan()` with the contract IR, schema IR, and additive-only policy
|
|
690
682
|
- On conflict: Returns a structured failure with conflict list
|
|
691
683
|
- On success: Returns a migration plan with operations
|
|
692
|
-
|
|
684
|
+
7. **Apply Migration** (if not `--plan`):
|
|
693
685
|
- Calls `runner.execute()` to apply the plan
|
|
686
|
+
- Runner executes pre/post checks for each operation
|
|
694
687
|
- After execution, verifies schema matches contract
|
|
695
|
-
- Writes contract marker
|
|
688
|
+
- Writes contract marker and ledger entry
|
|
696
689
|
|
|
697
690
|
**Output Format (TTY - Plan Mode):**
|
|
698
691
|
|
|
699
692
|
```
|
|
700
|
-
prisma-next db init ➜
|
|
693
|
+
prisma-next db init ➜ Initialize database schema from contract
|
|
701
694
|
config: prisma-next.config.ts
|
|
702
695
|
contract: src/prisma/contract.json
|
|
703
|
-
|
|
696
|
+
database: localhost:5432/mydb
|
|
704
697
|
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
├─ Create table user
|
|
708
|
-
├─
|
|
709
|
-
|
|
710
|
-
└─
|
|
698
|
+
Migration Plan (4 operations)
|
|
699
|
+
├─ Create extension "plpgsql"
|
|
700
|
+
├─ Create table "user"
|
|
701
|
+
│ ├─ id: int4 (not null, primary key)
|
|
702
|
+
│ └─ email: text (not null)
|
|
703
|
+
└─ Create unique index "user_email_key"
|
|
711
704
|
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
This is a dry run. No changes were applied.
|
|
715
|
-
Run without --plan to apply changes.
|
|
705
|
+
Run without --plan to apply this migration.
|
|
716
706
|
```
|
|
717
707
|
|
|
718
708
|
**Output Format (TTY - Apply Mode):**
|
|
719
709
|
|
|
720
710
|
```
|
|
721
|
-
prisma-next db init ➜
|
|
711
|
+
prisma-next db init ➜ Initialize database schema from contract
|
|
722
712
|
config: prisma-next.config.ts
|
|
723
713
|
contract: src/prisma/contract.json
|
|
714
|
+
database: localhost:5432/mydb
|
|
724
715
|
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
716
|
+
✔ Applied 4 migration operations
|
|
717
|
+
├─ Created extension "plpgsql"
|
|
718
|
+
├─ Created table "user"
|
|
719
|
+
└─ Created unique index "user_email_key"
|
|
720
|
+
✔ Contract marker written
|
|
721
|
+
coreHash: sha256:abc123...
|
|
722
|
+
✔ Ledger entry recorded
|
|
732
723
|
```
|
|
733
724
|
|
|
734
725
|
**Output Format (JSON):**
|
|
@@ -738,41 +729,33 @@ Applying migration plan and verifying schema...
|
|
|
738
729
|
"ok": true,
|
|
739
730
|
"mode": "apply",
|
|
740
731
|
"plan": {
|
|
741
|
-
"
|
|
742
|
-
"
|
|
743
|
-
"coreHash": "sha256:abc123..."
|
|
744
|
-
},
|
|
745
|
-
"operations": [
|
|
746
|
-
{
|
|
747
|
-
"id": "table.user",
|
|
748
|
-
"label": "Create table user",
|
|
749
|
-
"operationClass": "additive"
|
|
750
|
-
}
|
|
751
|
-
]
|
|
732
|
+
"operations": [...],
|
|
733
|
+
"conflicts": []
|
|
752
734
|
},
|
|
753
735
|
"execution": {
|
|
754
|
-
"
|
|
755
|
-
"
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
736
|
+
"operations": [...],
|
|
737
|
+
"marker": {
|
|
738
|
+
"coreHash": "sha256:abc123...",
|
|
739
|
+
"profileHash": "sha256:def456..."
|
|
740
|
+
},
|
|
741
|
+
"ledger": {
|
|
742
|
+
"id": "ledger-entry-uuid",
|
|
743
|
+
"createdAt": "2025-01-01T00:00:00Z"
|
|
744
|
+
}
|
|
759
745
|
}
|
|
760
746
|
}
|
|
761
747
|
```
|
|
762
748
|
|
|
763
749
|
**Error Codes:**
|
|
764
|
-
- `PN-CLI-
|
|
765
|
-
- `PN-CLI-
|
|
766
|
-
- `PN-CLI-
|
|
767
|
-
- `PN-CLI-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
- If the database already has a marker that matches the destination contract, `db init` succeeds as a noop (0 operations planned/executed).
|
|
775
|
-
- If the database has a marker that does **not** match the destination contract, `db init` fails (including in `--plan` mode). Use `db init` for bootstrapping; use your migration workflow to reconcile existing databases.
|
|
750
|
+
- `PN-CLI-4010`: Missing driver in config — provide a driver descriptor
|
|
751
|
+
- `PN-CLI-4011`: Missing database URL — provide `--db` flag or `config.db.url` or `DATABASE_URL` environment variable
|
|
752
|
+
- `PN-CLI-4011`: Migration planning failed due to conflicts (exit code 1)
|
|
753
|
+
- `PN-CLI-4012`: Target does not support migrations
|
|
754
|
+
|
|
755
|
+
**Current Limitations (v1):**
|
|
756
|
+
- Only supports empty databases (no existing tables)
|
|
757
|
+
- Non-empty databases result in a planning failure with conflict details
|
|
758
|
+
- Future `db update` command will support additive changes to existing schemas
|
|
776
759
|
|
|
777
760
|
**Config File (`prisma-next.config.ts`):**
|
|
778
761
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"files": [
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"string-width": "^7.2.0",
|
|
20
20
|
"strip-ansi": "^7.1.2",
|
|
21
21
|
"wrap-ansi": "^9.0.2",
|
|
22
|
-
"@prisma-next/
|
|
23
|
-
"@prisma-next/
|
|
24
|
-
"@prisma-next/
|
|
25
|
-
"@prisma-next/utils": "0.
|
|
22
|
+
"@prisma-next/core-control-plane": "0.2.0",
|
|
23
|
+
"@prisma-next/emitter": "0.2.0",
|
|
24
|
+
"@prisma-next/contract": "0.2.0",
|
|
25
|
+
"@prisma-next/utils": "0.2.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "24.10.4",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"typescript": "^5.9.3",
|
|
32
32
|
"vite-tsconfig-paths": "^5.1.4",
|
|
33
33
|
"vitest": "^4.0.16",
|
|
34
|
-
"@prisma-next/sql-contract": "0.
|
|
35
|
-
"@prisma-next/sql-contract-emitter": "0.
|
|
36
|
-
"@prisma-next/sql-
|
|
37
|
-
"@prisma-next/
|
|
38
|
-
"@prisma-next/sql-
|
|
39
|
-
"@prisma-next/
|
|
34
|
+
"@prisma-next/sql-contract": "0.2.0",
|
|
35
|
+
"@prisma-next/sql-contract-emitter": "0.2.0",
|
|
36
|
+
"@prisma-next/sql-runtime": "0.2.0",
|
|
37
|
+
"@prisma-next/test-utils": "0.0.1",
|
|
38
|
+
"@prisma-next/sql-operations": "0.2.0",
|
|
39
|
+
"@prisma-next/sql-contract-ts": "0.2.0"
|
|
40
40
|
},
|
|
41
41
|
"exports": {
|
|
42
42
|
".": {
|