@famgia/omnify-laravel 0.0.113 → 0.0.114
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@famgia/omnify-laravel",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.114",
|
|
4
4
|
"description": "Laravel migration and TypeScript type generator for omnify-schema",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"README.md"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@famgia/omnify-types": "0.0.
|
|
29
|
-
"@famgia/omnify-core": "0.0.
|
|
30
|
-
"@famgia/omnify-atlas": "0.0.
|
|
28
|
+
"@famgia/omnify-types": "0.0.103",
|
|
29
|
+
"@famgia/omnify-core": "0.0.105",
|
|
30
|
+
"@famgia/omnify-atlas": "0.0.99"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "tsup",
|
|
@@ -7,6 +7,7 @@ alwaysApply: false
|
|
|
7
7
|
# Laravel Rules
|
|
8
8
|
|
|
9
9
|
> **Documentation:** `.claude/guides/laravel/`
|
|
10
|
+
> **Team Migration Guide:** `.claude/guides/laravel/migrations-team.md`
|
|
10
11
|
> **Specific Rules:** See also `laravel-controller.mdc`, `laravel-resource.mdc`, `laravel-request.mdc`, `laravel-testing.mdc`, `migrations-workflow.mdc`, `omnify-migrations.mdc`
|
|
11
12
|
|
|
12
13
|
## ⛔ CRITICAL: DO NOT EDIT
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
# Migration Team Workflow Guide
|
|
2
|
+
|
|
3
|
+
> Best practices for managing database migrations in team development environments.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Omnify follows **international standards** for database migration management:
|
|
8
|
+
|
|
9
|
+
1. **Schema as Source of Truth** - YAML schemas define the database structure
|
|
10
|
+
2. **Simple File Tracking** - Lock file tracks migrations for regeneration
|
|
11
|
+
3. **CI Validation** - Automated checks ensure sync between schema and migrations
|
|
12
|
+
4. **Git for Conflict Resolution** - Standard Git workflow handles merge conflicts
|
|
13
|
+
|
|
14
|
+
## Migration Tracking System
|
|
15
|
+
|
|
16
|
+
### Lock File Structure
|
|
17
|
+
|
|
18
|
+
The `.omnify.lock` file tracks all generated migrations:
|
|
19
|
+
|
|
20
|
+
```json
|
|
21
|
+
{
|
|
22
|
+
"version": 2,
|
|
23
|
+
"migrations": [
|
|
24
|
+
{
|
|
25
|
+
"fileName": "2026_01_13_100000_create_users_table.php",
|
|
26
|
+
"timestamp": "2026_01_13_100000",
|
|
27
|
+
"tableName": "users",
|
|
28
|
+
"type": "create",
|
|
29
|
+
"generatedAt": "2026-01-13T10:00:00Z",
|
|
30
|
+
"schemas": ["User"],
|
|
31
|
+
"checksum": "sha256..."
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Key Fields
|
|
38
|
+
|
|
39
|
+
| Field | Purpose |
|
|
40
|
+
|-------|---------|
|
|
41
|
+
| `fileName` | Full migration filename |
|
|
42
|
+
| `timestamp` | Timestamp prefix for regeneration |
|
|
43
|
+
| `tableName` | Table name for lookup |
|
|
44
|
+
| `type` | Migration type (create/alter/drop/pivot) |
|
|
45
|
+
| `checksum` | SHA-256 hash for integrity verification |
|
|
46
|
+
|
|
47
|
+
## CI/CD Integration
|
|
48
|
+
|
|
49
|
+
### GitHub Actions Example
|
|
50
|
+
|
|
51
|
+
```yaml
|
|
52
|
+
# .github/workflows/migration-check.yml
|
|
53
|
+
name: Migration Check
|
|
54
|
+
|
|
55
|
+
on: [push, pull_request]
|
|
56
|
+
|
|
57
|
+
jobs:
|
|
58
|
+
validate:
|
|
59
|
+
runs-on: ubuntu-latest
|
|
60
|
+
steps:
|
|
61
|
+
- uses: actions/checkout@v4
|
|
62
|
+
|
|
63
|
+
- name: Setup Node.js
|
|
64
|
+
uses: actions/setup-node@v4
|
|
65
|
+
with:
|
|
66
|
+
node-version: '20'
|
|
67
|
+
|
|
68
|
+
- name: Install dependencies
|
|
69
|
+
run: npm ci
|
|
70
|
+
|
|
71
|
+
- name: Check migrations sync
|
|
72
|
+
run: npx omnify generate --check
|
|
73
|
+
|
|
74
|
+
- name: Test migrations (optional)
|
|
75
|
+
run: |
|
|
76
|
+
php artisan migrate:fresh --force
|
|
77
|
+
php artisan migrate:status
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### CI Check Mode
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# Check if migrations are in sync (for CI)
|
|
84
|
+
npx omnify generate --check
|
|
85
|
+
|
|
86
|
+
# Exit codes:
|
|
87
|
+
# 0 = All migrations in sync ✅
|
|
88
|
+
# 1 = Schema changes detected or migration issues ❌
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Output example:
|
|
92
|
+
```
|
|
93
|
+
Omnify v1.0.113 - Generating Outputs
|
|
94
|
+
|
|
95
|
+
✔ Loading schemas from schemas
|
|
96
|
+
✔ Validating schemas...
|
|
97
|
+
✔ Checking for changes...
|
|
98
|
+
|
|
99
|
+
CI Check Mode Results:
|
|
100
|
+
Schemas: 12
|
|
101
|
+
Tracked migrations: 15
|
|
102
|
+
Migrations on disk: 15
|
|
103
|
+
Schema changes: 0
|
|
104
|
+
|
|
105
|
+
✅ All migrations in sync
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Team Development Workflow
|
|
109
|
+
|
|
110
|
+
### Standard Workflow
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
114
|
+
│ 1. Edit YAML Schema │
|
|
115
|
+
│ schemas/module/Model.yaml │
|
|
116
|
+
└─────────────────────────────────────────────────────────────┘
|
|
117
|
+
│
|
|
118
|
+
▼
|
|
119
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
120
|
+
│ 2. Generate Migrations │
|
|
121
|
+
│ npx omnify generate │
|
|
122
|
+
└─────────────────────────────────────────────────────────────┘
|
|
123
|
+
│
|
|
124
|
+
▼
|
|
125
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
126
|
+
│ 3. Commit Both │
|
|
127
|
+
│ git add schemas/ database/migrations/ .omnify.lock │
|
|
128
|
+
│ git commit -m "feat: add phone field to User" │
|
|
129
|
+
└─────────────────────────────────────────────────────────────┘
|
|
130
|
+
│
|
|
131
|
+
▼
|
|
132
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
133
|
+
│ 4. CI Validates │
|
|
134
|
+
│ GitHub Actions runs: npx omnify generate --check │
|
|
135
|
+
└─────────────────────────────────────────────────────────────┘
|
|
136
|
+
│
|
|
137
|
+
▼
|
|
138
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
139
|
+
│ 5. Merge & Deploy │
|
|
140
|
+
│ php artisan migrate │
|
|
141
|
+
└─────────────────────────────────────────────────────────────┘
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Parallel Development
|
|
145
|
+
|
|
146
|
+
When multiple developers work on different schemas:
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
Developer A Developer B
|
|
150
|
+
│ │
|
|
151
|
+
Edit User.yaml Edit Product.yaml
|
|
152
|
+
(add phone) (add sku)
|
|
153
|
+
│ │
|
|
154
|
+
omnify generate omnify generate
|
|
155
|
+
│ │
|
|
156
|
+
Creates: Creates:
|
|
157
|
+
alter_users_add_phone.php alter_products_add_sku.php
|
|
158
|
+
│ │
|
|
159
|
+
└──────────┬───────────────────┘
|
|
160
|
+
│
|
|
161
|
+
Git Merge
|
|
162
|
+
│
|
|
163
|
+
Both migrations exist ✅
|
|
164
|
+
(different tables, no conflict)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Same Schema Conflict
|
|
168
|
+
|
|
169
|
+
When multiple developers edit the SAME schema:
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
Developer A Developer B
|
|
173
|
+
│ │
|
|
174
|
+
Edit User.yaml Edit User.yaml
|
|
175
|
+
(add phone) (add address)
|
|
176
|
+
│ │
|
|
177
|
+
omnify generate omnify generate
|
|
178
|
+
│ │
|
|
179
|
+
└──────────┬───────────────────┘
|
|
180
|
+
│
|
|
181
|
+
Git Merge
|
|
182
|
+
│
|
|
183
|
+
⚠️ YAML Conflict!
|
|
184
|
+
│
|
|
185
|
+
┌──────────┴──────────┐
|
|
186
|
+
│ │
|
|
187
|
+
Resolve YAML Keep both migrations
|
|
188
|
+
(merge both fields) (Laravel runs both)
|
|
189
|
+
│ │
|
|
190
|
+
└──────────┬──────────┘
|
|
191
|
+
│
|
|
192
|
+
Result:
|
|
193
|
+
User.yaml has phone + address
|
|
194
|
+
Both migrations exist
|
|
195
|
+
Laravel runs in timestamp order ✅
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## Handling Common Scenarios
|
|
199
|
+
|
|
200
|
+
### Scenario 1: Accidentally Deleted Migration
|
|
201
|
+
|
|
202
|
+
**Problem:** Migration file deleted but lock file still tracks it.
|
|
203
|
+
|
|
204
|
+
**Detection:**
|
|
205
|
+
```bash
|
|
206
|
+
npx omnify generate
|
|
207
|
+
|
|
208
|
+
⚠️ Migration file issues detected:
|
|
209
|
+
Missing files (1):
|
|
210
|
+
- 2026_01_13_100000_create_users_table.php
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
**Solutions:**
|
|
214
|
+
```bash
|
|
215
|
+
# Option 1: Restore from git
|
|
216
|
+
git checkout -- database/migrations/omnify/
|
|
217
|
+
|
|
218
|
+
# Option 2: Reset and regenerate (destructive!)
|
|
219
|
+
npx omnify reset --migrations
|
|
220
|
+
npx omnify generate --force
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Scenario 2: Stale Migration from Old Branch
|
|
224
|
+
|
|
225
|
+
**Problem:** Branch created 1 month ago, merged today with old timestamp.
|
|
226
|
+
|
|
227
|
+
**Detection:**
|
|
228
|
+
```bash
|
|
229
|
+
npx omnify generate
|
|
230
|
+
|
|
231
|
+
⚠️ Stale migrations detected (old timestamp, not in lock file):
|
|
232
|
+
- 2026_01_04_100000_add_phone_to_users_table.php
|
|
233
|
+
These may be from merged branches. Review before running migrate.
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
**Action:**
|
|
237
|
+
1. Review the migration - is it independent or dependent?
|
|
238
|
+
2. If independent: Keep as-is, Laravel runs in timestamp order
|
|
239
|
+
3. If dependent: Consider renaming with new timestamp
|
|
240
|
+
|
|
241
|
+
### Scenario 3: CI Fails with "Schema changes detected"
|
|
242
|
+
|
|
243
|
+
**Problem:** Someone edited schema but forgot to run generate.
|
|
244
|
+
|
|
245
|
+
**Detection:**
|
|
246
|
+
```bash
|
|
247
|
+
npx omnify generate --check
|
|
248
|
+
|
|
249
|
+
❌ Schema changes detected - run "npx omnify generate" to update migrations
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
**Solution:**
|
|
253
|
+
```bash
|
|
254
|
+
# Locally
|
|
255
|
+
npx omnify generate
|
|
256
|
+
git add .
|
|
257
|
+
git commit --amend # or new commit
|
|
258
|
+
git push --force # or regular push
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## Best Practices
|
|
262
|
+
|
|
263
|
+
### DO ✅
|
|
264
|
+
|
|
265
|
+
1. **Always commit schema + migrations together**
|
|
266
|
+
```bash
|
|
267
|
+
git add schemas/ database/migrations/omnify/ .omnify.lock
|
|
268
|
+
git commit -m "feat: add field to schema"
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
2. **Use CI to validate migrations**
|
|
272
|
+
```bash
|
|
273
|
+
npx omnify generate --check
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
3. **Pull and migrate before starting new work**
|
|
277
|
+
```bash
|
|
278
|
+
git pull
|
|
279
|
+
php artisan migrate
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
4. **Review stale migration warnings**
|
|
283
|
+
- Check dependencies before merging old branches
|
|
284
|
+
|
|
285
|
+
### DON'T ❌
|
|
286
|
+
|
|
287
|
+
1. **Don't manually edit migrations in `omnify/` folder**
|
|
288
|
+
- They will be overwritten!
|
|
289
|
+
|
|
290
|
+
2. **Don't ignore CI failures**
|
|
291
|
+
- Always run `npx omnify generate` if CI fails
|
|
292
|
+
|
|
293
|
+
3. **Don't commit migrations without schemas**
|
|
294
|
+
- Schema is source of truth
|
|
295
|
+
|
|
296
|
+
4. **Don't skip stale warnings without review**
|
|
297
|
+
- Old timestamps might run before dependent migrations
|
|
298
|
+
|
|
299
|
+
## Migration Validation
|
|
300
|
+
|
|
301
|
+
### Check Commands
|
|
302
|
+
|
|
303
|
+
```bash
|
|
304
|
+
# Full check (for CI)
|
|
305
|
+
npx omnify generate --check
|
|
306
|
+
|
|
307
|
+
# Generate with stale warnings (default)
|
|
308
|
+
npx omnify generate
|
|
309
|
+
|
|
310
|
+
# Generate without stale warnings
|
|
311
|
+
npx omnify generate --no-warn-stale
|
|
312
|
+
|
|
313
|
+
# Force regenerate everything
|
|
314
|
+
npx omnify generate --force
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### Validation Checks
|
|
318
|
+
|
|
319
|
+
| Check | Description | Exit Code |
|
|
320
|
+
|-------|-------------|-----------|
|
|
321
|
+
| Schema sync | Schema matches generated migrations | 1 if mismatch |
|
|
322
|
+
| Missing files | Migration files exist on disk | 1 if missing |
|
|
323
|
+
| Modified files | Files match stored checksum | Warning only |
|
|
324
|
+
| Stale files | Old timestamp, not tracked | Warning only |
|
|
325
|
+
|
|
326
|
+
## Troubleshooting
|
|
327
|
+
|
|
328
|
+
### "Missing migration files"
|
|
329
|
+
|
|
330
|
+
```bash
|
|
331
|
+
# Check what's missing
|
|
332
|
+
npx omnify generate --check
|
|
333
|
+
|
|
334
|
+
# Restore from git
|
|
335
|
+
git checkout -- database/migrations/omnify/
|
|
336
|
+
|
|
337
|
+
# Or reset completely
|
|
338
|
+
npx omnify reset --migrations
|
|
339
|
+
npx omnify generate --force
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
### "Checksum mismatch"
|
|
343
|
+
|
|
344
|
+
Someone manually edited an auto-generated file.
|
|
345
|
+
|
|
346
|
+
```bash
|
|
347
|
+
# Option 1: Regenerate
|
|
348
|
+
npx omnify generate --force
|
|
349
|
+
|
|
350
|
+
# Option 2: Reset lock file entry
|
|
351
|
+
# (manually edit .omnify.lock to remove the entry)
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### "Stale migrations"
|
|
355
|
+
|
|
356
|
+
Old branch merged with old timestamps.
|
|
357
|
+
|
|
358
|
+
```bash
|
|
359
|
+
# Usually safe to ignore if migrations are independent
|
|
360
|
+
# But review the migration order:
|
|
361
|
+
|
|
362
|
+
php artisan migrate:status
|
|
363
|
+
# Check: Will the old migration run before something it depends on?
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
## Summary
|
|
367
|
+
|
|
368
|
+
| Workflow Step | Command |
|
|
369
|
+
|---------------|---------|
|
|
370
|
+
| Edit schema | Edit `schemas/*.yaml` |
|
|
371
|
+
| Generate | `npx omnify generate` |
|
|
372
|
+
| Commit | `git add schemas/ database/migrations/ .omnify.lock` |
|
|
373
|
+
| CI Check | `npx omnify generate --check` |
|
|
374
|
+
| Deploy | `php artisan migrate` |
|
|
375
|
+
| Restore | `git checkout -- database/migrations/omnify/` |
|
|
376
|
+
| Reset | `npx omnify reset --migrations` |
|