prisma-laravel-migrate 0.0.6 → 0.0.7

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.
Files changed (2) hide show
  1. package/README.md +128 -158
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Prisma Laravel Migrate
2
2
 
3
- A generator toolkit that translates your **Prisma schema** into Laravel-compatible
3
+ A generator plugin that translates your **Prisma schema** into Laravel‑ready
4
4
  **Database Migrations**, **Eloquent Models**, and **Enum classes**.
5
- Everything is written in strict TypeScript and fully customizable through stubs, grouping, and marker-based injection.
5
+ Built in strict TypeScript with fully‑customisable stubs, grouping, and markerbased updates.
6
6
 
7
7
  ---
8
8
 
@@ -10,176 +10,167 @@ Everything is written in strict TypeScript and fully customizable through stubs,
10
10
 
11
11
  ```bash
12
12
  npm install prisma-laravel-migrate --save-dev
13
-
14
- (Requires prisma in the same project.)
15
-
13
+ # requires the Prisma CLI in your project
14
+ ```
16
15
 
17
16
  ---
18
17
 
19
- 🛠️ Prisma Generator Setup
18
+ ## 🛠️ Prisma Generator Setup
20
19
 
21
- Insert two generator blocks in schema.prisma:
20
+ Add both generator blocks to **`schema.prisma`**:
22
21
 
22
+ ```prisma
23
23
  generator migrate {
24
24
  provider = "prisma-laravel-migrate"
25
25
  stubDir = "./prisma/stubs"
26
- output = "database/migrations" // fallback
27
- outputDir = "database/migrations" // takes precedence
26
+ output = "database/migrations" // fallback
27
+ outputDir = "database/migrations" // takes precedence
28
28
  startMarker = "// <prisma-laravel:start>"
29
29
  endMarker = "// <prisma-laravel:end>"
30
- noEmit = false // set true to skip writing files
31
- groups = "./prisma/group-stubs.js" // optional group mapping
30
+ noEmit = false
31
+ groups = "./prisma/group-stubs.js"
32
32
  }
33
33
 
34
34
  generator modeler {
35
35
  provider = "prisma-laravel-models"
36
36
  stubDir = "./prisma/stubs"
37
37
  output = "app/Models"
38
- outputDir = "app/Models" // takes precedence
39
- outputEnumDir = "app/Enums" // enums folder (optional)
38
+ outputDir = "app/Models" // overrides output
39
+ outputEnumDir = "app/Enums"
40
40
  startMarker = "// <prisma-laravel:start>"
41
41
  endMarker = "// <prisma-laravel:end>"
42
42
  noEmit = false
43
43
  groups = "./prisma/group-stubs.js"
44
44
  }
45
+ ```
45
46
 
46
- Field Reference
47
-
48
- Key Notes
49
-
50
- output / outputDir Destination folder; outputDir overrides output.
51
- outputEnumDir (modeler) folder for PHP enum classes.
52
- stubDir Root stubs folder (migration/, model/, enum/).
53
- startMarker / endMarker Region markers the generator will update.
54
- groups Path to JS module exporting stub-group mappings.
55
- noEmit If true, generator parses but writes no files.
56
-
47
+ ### Field Reference
57
48
 
49
+ | Key | Notes |
50
+ | --- | --- |
51
+ | `outputDir / output` | Destination folder (`outputDir` takes precedence). |
52
+ | `outputEnumDir` | (modeler) directory for PHP enum classes. |
53
+ | `stubDir` | Root stubs folder (`migration/`, `model/`, `enum/`). |
54
+ | `startMarker/endMarker` | Region markers the generator will update. |
55
+ | `groups` | JS module exporting stub‑group mappings. |
56
+ | `noEmit` | If `true`, generator parses but **writes no** files. |
58
57
 
59
58
  ---
60
59
 
61
- 📁 Stub Folder Layout
62
-
63
- Running
64
-
65
- npx prisma-laravel-cli init --schema=prisma/schema.prisma
66
-
67
- creates:
60
+ ## 📁 Stub Folder Layout
68
61
 
62
+ ```
69
63
  prisma/stubs/
70
64
  ├── migration/index.stub
71
65
  ├── model/index.stub
72
66
  ├── model/simple-model.stub
73
67
  └── enum/index.stub
68
+ ```
74
69
 
75
- Copy log (example):
76
-
77
- ➡️ Copied migration.stub → stubs/migration/index.stub
78
- ➡️ Copied model.stub → stubs/model/index.stub
79
- ➡️ Copied enums.stub → stubs/enum/index.stub
80
- ➡️ Copied simple-model.stub → stubs/model/simple-model.stub
81
-
82
- Override a single table / enum by adding
83
- stubs/<type>/<name>.stub (e.g. stubs/model/users.stub).
84
-
70
+ Create a table‑specific override with
71
+ `stubs/<type>/<table>.stub` (e.g. `stubs/model/users.stub`).
85
72
 
86
73
  ---
87
74
 
88
- 🔧 CLI Commands
75
+ ## 🔧 CLI Commands
89
76
 
90
- Command Purpose
77
+ | Command | What it does |
78
+ | --- | --- |
79
+ | `init` | Inject generator blocks & scaffold stub folders |
80
+ | `customize` | Create per‑table stub overrides |
81
+ | `gen` | Run `prisma generate` then Laravel generators |
91
82
 
92
- init Injects generator blocks & scaffold stub folders.
93
- customize Create per-table stub overrides.
94
- gen Run prisma generate and then Laravel generators.
95
-
96
-
97
- init
83
+ ### init
98
84
 
85
+ ```bash
99
86
  npx prisma-laravel-cli init --schema=prisma/schema.prisma
87
+ ```
100
88
 
101
- customize
89
+ ### customize
102
90
 
103
- # create migration+model overrides for users & accounts
104
- npx prisma-laravel-cli customize -t migration,model -n users,accounts
91
+ Generate override stubs.
105
92
 
106
- # create enum overrides
107
- npx prisma-laravel-cli customize -t enum -n UserStatus,RoleType
93
+ ```bash
94
+ npx prisma-laravel-cli customize \
95
+ -t <types> \
96
+ -n <names> \
97
+ [--force] \
98
+ [--config <path>]
99
+ ```
100
+
101
+ | Flag | Description |
102
+ | --- | --- |
103
+ | `-t, --type` | **Required.** Comma‑separated list of stub types.<br>Valid values: `migration`, `model`, `enum`. You may combine `migration,model`; `enum` must be used alone. |
104
+ | `-n, --names` | **Required.** Comma‑separated table or enum names (e.g. `users,accounts`). |
105
+ | `--force` | Overwrite existing stub files. |
106
+ | `--config` | Path to an alternate CLI config file (custom stubDir/groups). |
107
+
108
+ **Behaviour**
109
+
110
+ 1. Checks `<stubDir>/<type>/<name>.stub`.
111
+ 2. If missing, copies from `index.stub` → that path and logs:
112
+ `➡️ Created stubs/<type>/<name>.stub from index.stub`
113
+ 3. If present and `--force` **not** set:
114
+ `⏭️ Skipped existing stubs/<type>/<name>.stub`
115
+ 4. With `--force`, overwrites and logs creation.
116
+
117
+ **Example**
108
118
 
109
- migration & model may be combined; enum must be separate.
119
+ ```bash
120
+ # migration + model overrides for two tables
121
+ npx prisma-laravel-cli customize -t migration,model -n users,accounts
122
+ ```
110
123
 
111
- gen
124
+ ### gen
112
125
 
113
- # run prisma generate then Laravel generation
126
+ ```bash
127
+ # run prisma generate then Laravel generators
114
128
  npx prisma-laravel-cli gen --config=prisma/laravel.config.js
115
129
 
116
130
  # skip prisma generate step
117
131
  npx prisma-laravel-cli gen --config=prisma/laravel.config.js --skipGenerate
132
+ ```
118
133
 
119
- prisma/laravel.config.js example:
134
+ `prisma/laravel.config.js` example:
120
135
 
136
+ ```js
121
137
  module.exports = {
122
138
  migrator: {
123
- outputDir: 'database/migrations',
124
- stubDir: 'prisma/stubs',
125
- groups: './prisma/group-stubs.js',
139
+ outputDir: "database/migrations",
140
+ stubDir: "prisma/stubs",
141
+ groups: "./prisma/group-stubs.js",
126
142
  },
127
143
  modeler: {
128
- outputDir: 'app/Models',
129
- outputEnumDir: 'app/Enums',
130
- stubDir: 'prisma/stubs',
131
- groups: './prisma/group-stubs.js',
144
+ outputDir: "app/Models",
145
+ outputEnumDir: "app/Enums",
146
+ stubDir: "prisma/stubs",
147
+ groups: "./prisma/group-stubs.js",
132
148
  },
133
149
  };
134
-
150
+ ```
135
151
 
136
152
  ---
137
153
 
138
- 🧩 Grouping Stubs
139
-
140
- prisma/group-stubs.js
141
-
142
- module.exports = [
143
- { stubFile: 'auth.stub', tables: ['users','accounts','password_resets'] },
144
- { stubFile: 'billing.stub', tables: ['invoices','transactions'] },
145
- ];
146
-
147
- Resolution order
148
-
149
- 1. stubs/<type>/<table>.stub
150
-
151
-
152
- 2. Matching group stub (stubFile)
153
-
154
-
155
- 3. stubs/<type>/index.stub
156
-
154
+ ## Stub Customization Notes
157
155
 
156
+ Stubs are **JS template literals**. Escape \\` and \\${ } if you want them literally.
158
157
 
158
+ > **Full custom model stubs**
159
+ > If you plan to hand-craft **all** the internal sections yourself
160
+ > (fillable, hidden, casts, etc.), remove the `${content}` placeholder
161
+ > but **keep** the `// <prisma-laravel:start>` and
162
+ > `// <prisma-laravel:end>` markers so the generator still knows where
163
+ > to inject future updates.
164
+ > Remove the markers only if you never want the file touched again
159
165
 
160
166
  ---
161
167
 
162
- Stub Customization Notes
163
-
164
- Stubs are JavaScript template literals. Escape \` and \${ } if you need them literally.
168
+ ## 📑 Default Stub Templates
165
169
 
166
- Keep the ${content} placeholder inside the marker block if you want the generator to keep injecting its dynamic chunk.
167
-
168
- > Full Custom Model Stubs
169
- If you plan to hand-craft a model stub completely—removing both the ${content} placeholder and the // <prisma-laravel:start> / // <prisma-laravel:end> markers—set
170
- noEmit = true for the modeler generator (or exclude that table via custom rules).
171
- Otherwise, the generator has nowhere to inject its code and will skip the file.
172
- Leaving the markers + ${content} lets you customise everything around the generated region while the tool continues to maintain fillable lists, casts, and relations automatically.
173
-
174
-
175
-
176
-
177
- ---
178
-
179
- 📑 Default Stub Templates
180
-
181
- Enum
170
+ <details>
171
+ <summary>Enum <code>index.stub</code></summary>
182
172
 
173
+ ```php
183
174
  <?php
184
175
 
185
176
  namespace App\\Enums;
@@ -190,9 +181,14 @@ enum ${enumDef.name}: string
190
181
  ${enumDef.values.map(v => ` case ${v} = '${v}';`).join('\\n')}
191
182
  // <prisma-laravel:end>
192
183
  }
184
+ ```
193
185
 
194
- Migration
186
+ </details>
195
187
 
188
+ <details>
189
+ <summary>Migration <code>index.stub</code></summary>
190
+
191
+ ```php
196
192
  <?php
197
193
 
198
194
  use Illuminate\\Database\\Migrations\\Migration;
@@ -215,12 +211,18 @@ return new class extends Migration
215
211
  Schema::dropIfExists('${tableName}');
216
212
  }
217
213
  };
214
+ ```
218
215
 
216
+ </details>
219
217
 
220
218
  ---
221
219
 
222
- 🏗️ Complex Model Stub Example
220
+ ## 🏗️ Complex Model Stub Example
221
+
222
+ <details>
223
+ <summary>Expand stub</summary>
223
224
 
225
+ ```php
224
226
  <?php
225
227
 
226
228
  namespace App\\Models;
@@ -233,7 +235,7 @@ class ${model.className} extends Model
233
235
  {
234
236
  protected $table = '${model.tableName}';
235
237
 
236
- /* ---------- Mass Assignment ---------- */
238
+ /* Mass Assignment */
237
239
  protected $fillable = [
238
240
  ${model.properties.filter(p => p.fillable).map(p => ` '${p.name}',`).join('\\n')}
239
241
  ];
@@ -241,7 +243,7 @@ ${model.properties.filter(p => p.fillable).map(p => ` '${p.name}',`).join
241
243
  ${(model.guarded ?? []).map(n => ` '${n}',`).join('\\n')}
242
244
  ];
243
245
 
244
- /* ---------- Hidden / Casts ---------- */
246
+ /* Hidden & Casts */
245
247
  protected $hidden = [
246
248
  ${model.properties.filter(p => p.hidden).map(p => ` '${p.name}',`).join('\\n')}
247
249
  ];
@@ -250,80 +252,48 @@ ${model.properties.filter(p => p.cast).map(p => ` '${p.name}' => '${p.cas
250
252
  ${model.properties.filter(p => p.enumRef).map(p => ` '${p.name}' => ${p.enumRef}::class,`).join('\\n')}
251
253
  ];
252
254
 
253
- /* ---------- Eager Loading ---------- */
254
- protected $with = [
255
- ${(model.with ?? []).map(r => ` '${r}',`).join('\\n')}
256
- ];
257
-
258
- /* ---------- Interfaces ---------- */
255
+ /* Interfaces metadata */
259
256
  public array $interfaces = [
260
- ${Object.entries(model.interfaces).map(([k,i]) => ` '${k}' => {${i.import ? ` import: '${i.import}',` : ''} type: '${i.type}' },`).join('\\n')}
257
+ ${Object.entries(model.interfaces).map(([k,i]) =>
258
+ ` '${k}' => {${i.import ? ` import: '${i.import}',` : ''} type: '${i.type}' },`).join('\\n')}
261
259
  ];
260
+ // This structure is useful for packages like fumeapp/modeltyper which
261
+ // read interface metadata to build TypeScript helpers.
262
262
 
263
- /* ---------- Relationships ---------- */
263
+ /* Relationships */
264
264
  ${model.relations.map(r => {
265
265
  const args = [r.modelClass, r.foreignKey ? `'${r.foreignKey}'` : '', r.localKey ? `'${r.localKey}'` : ''].filter(Boolean).join(', ');
266
- return ` public function ${r.name}(): ${r.type.charAt(0).toUpperCase() + r.type.slice(1)}\\n {\\n return $this->${r.type}(${args});\\n }`;
266
+ return ` public function ${r.name}(): ${r.type.charAt(0).toUpperCase()+r.type.slice(1)}\\n {\\n return $this->${r.type}(${args});\\n }`;
267
267
  }).join('\\n\\n')}
268
268
 
269
269
  // <prisma-laravel:start>
270
270
  ${content}
271
271
  // <prisma-laravel:end>
272
272
  }
273
+ ```
273
274
 
275
+ </details>
274
276
 
275
277
  ---
276
278
 
277
- 📚 Interfaces Metadata Example
278
-
279
- Useful for fumeapp/modeltyper integration:
280
-
281
- public array $interfaces = [
282
- 'props' => [
283
- 'import' => \"@typings/service-forms\",
284
- 'type' => 'ServiceProps',
285
- ],
286
- 'services' => [
287
- 'type' => 'Array<SMMService>',
288
- ],
289
- ];
290
-
291
- Type definition:
292
- Record<string, { import?: string; type: string }>.
293
-
294
-
295
- ---
296
-
297
- 🚀 Enum Casting
298
-
299
- The generator automatically casts Prisma enums:
279
+ ## 🚀 Enum Casting
300
280
 
281
+ ```php
301
282
  protected $casts = [
302
283
  'status' => StatusEnum::class,
303
284
  ];
304
-
305
- Enums are saved to outputEnumDir if configured.
306
-
307
-
308
- ---
309
-
310
- 💡 Tips
311
-
312
- Combine migration & model in the same customize command when table names align.
313
-
314
- Escape template characters in stub files.
315
-
316
- Use noEmit: true for dry-runs or CI validation.
317
-
318
-
285
+ ```
319
286
 
320
287
  ---
321
288
 
322
- 📜 License
289
+ ## 💡 Tips
323
290
 
324
- MIT Happy scaffolding! 🎉
291
+ - Combine `migration` & `model` in one customize command when table names align.
292
+ - Use `noEmit: true` for dry‑runs or CI validation.
293
+ - Escape template chars in stub files.
325
294
 
326
295
  ---
327
296
 
328
- Copy that entire block into **README.md** and you’ll have the corrected, full documentation—including the note about fully custom model stubs.
297
+ ## 📜 License
329
298
 
299
+ MIT — Happy scaffolding! 🎉
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-laravel-migrate",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Generate laravel migrations and/or models using prisma files",
5
5
  "bin": {
6
6
  "prisma-laravel-migrations": "./dist/cli/index.js",