sonamu 0.10.7 → 0.10.9

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 (79) hide show
  1. package/dist/api/decorators.d.ts.map +1 -1
  2. package/dist/api/decorators.js +5 -12
  3. package/dist/bin/cli.js +10 -253
  4. package/dist/database/base-model.d.ts +1 -0
  5. package/dist/database/base-model.d.ts.map +1 -1
  6. package/dist/database/base-model.js +14 -8
  7. package/dist/database/db.d.ts +2 -1
  8. package/dist/database/db.d.ts.map +1 -1
  9. package/dist/database/db.js +13 -3
  10. package/dist/database/puri-wrapper.d.ts.map +1 -1
  11. package/dist/database/puri-wrapper.js +4 -11
  12. package/dist/database/transaction-context.d.ts +8 -3
  13. package/dist/database/transaction-context.d.ts.map +1 -1
  14. package/dist/database/transaction-context.js +12 -7
  15. package/dist/migration/code-generation.js +2 -2
  16. package/dist/naite/naite-reporter.d.ts +8 -3
  17. package/dist/naite/naite-reporter.d.ts.map +1 -1
  18. package/dist/naite/naite-reporter.js +9 -4
  19. package/dist/ui-web/assets/{index-D0MHYbxl.js → index-CJf8uJYf.js} +47 -41
  20. package/dist/ui-web/assets/index-GMMIVGja.css +1 -0
  21. package/dist/ui-web/index.html +2 -2
  22. package/package.json +3 -3
  23. package/src/api/decorators.ts +11 -22
  24. package/src/bin/cli.ts +12 -375
  25. package/src/database/__tests__/transaction-scope.test.ts +227 -0
  26. package/src/database/base-model.ts +31 -6
  27. package/src/database/db.ts +17 -2
  28. package/src/database/puri-wrapper.ts +5 -22
  29. package/src/database/transaction-context.ts +14 -6
  30. package/src/migration/code-generation.ts +1 -1
  31. package/src/naite/naite-reporter.ts +8 -3
  32. package/dist/ui-web/assets/index-Dx_JX4aQ.css +0 -1
  33. package/src/skills/AGENTS.md +0 -108
  34. package/src/skills/sonamu/SKILL.md +0 -75
  35. package/src/skills/sonamu-ai-agents/SKILL.md +0 -205
  36. package/src/skills/sonamu-api/SKILL.md +0 -480
  37. package/src/skills/sonamu-auth/SKILL.md +0 -327
  38. package/src/skills/sonamu-auth/references/plugins.md +0 -310
  39. package/src/skills/sonamu-auth/references/user-id-migration-followups.md +0 -192
  40. package/src/skills/sonamu-auth/references/user-id-migration.md +0 -455
  41. package/src/skills/sonamu-config/SKILL.md +0 -203
  42. package/src/skills/sonamu-config/references/database.md +0 -452
  43. package/src/skills/sonamu-config/references/environments.md +0 -178
  44. package/src/skills/sonamu-config/references/server-options.md +0 -400
  45. package/src/skills/sonamu-entity/SKILL.md +0 -180
  46. package/src/skills/sonamu-entity/references/creation-workflow.md +0 -581
  47. package/src/skills/sonamu-entity/references/design-guides.md +0 -243
  48. package/src/skills/sonamu-entity/references/field-types.md +0 -170
  49. package/src/skills/sonamu-entity/references/relations-detail.md +0 -245
  50. package/src/skills/sonamu-entity/references/relations.md +0 -463
  51. package/src/skills/sonamu-entity/references/subset.md +0 -156
  52. package/src/skills/sonamu-fixture/SKILL.md +0 -180
  53. package/src/skills/sonamu-fixture/references/cli-usage.md +0 -439
  54. package/src/skills/sonamu-fixture/references/cone.md +0 -298
  55. package/src/skills/sonamu-frontend/SKILL.md +0 -142
  56. package/src/skills/sonamu-frontend/references/components.md +0 -323
  57. package/src/skills/sonamu-frontend/references/examples.md +0 -64
  58. package/src/skills/sonamu-frontend/references/hooks.md +0 -273
  59. package/src/skills/sonamu-frontend/references/runtime.md +0 -165
  60. package/src/skills/sonamu-frontend/references/scaffolding.md +0 -439
  61. package/src/skills/sonamu-i18n/SKILL.md +0 -287
  62. package/src/skills/sonamu-migration/SKILL.md +0 -316
  63. package/src/skills/sonamu-naite/SKILL.md +0 -266
  64. package/src/skills/sonamu-query/SKILL.md +0 -48
  65. package/src/skills/sonamu-query/references/model-patterns.md +0 -390
  66. package/src/skills/sonamu-query/references/model.md +0 -366
  67. package/src/skills/sonamu-query/references/puri.md +0 -413
  68. package/src/skills/sonamu-query/references/search.md +0 -238
  69. package/src/skills/sonamu-query/references/upsert.md +0 -324
  70. package/src/skills/sonamu-tasks/SKILL.md +0 -236
  71. package/src/skills/sonamu-testing/SKILL.md +0 -251
  72. package/src/skills/sonamu-testing/references/devrunner.md +0 -405
  73. package/src/skills/sonamu-testing/references/helpers.md +0 -185
  74. package/src/skills/sonamu-testing/references/patterns.md +0 -263
  75. package/src/skills/sonamu-testing/references/pitfalls.md +0 -588
  76. package/src/skills/sonamu-testing/references/quick-start.md +0 -285
  77. package/src/skills/sonamu-testing/references/type-safety.md +0 -172
  78. package/src/skills/sonamu-testing/references/writing-plan.md +0 -375
  79. package/src/skills/sonamu-vector/SKILL.md +0 -222
@@ -1,180 +0,0 @@
1
- ---
2
- name: sonamu-fixture
3
- description: Generates and manages Sonamu test data. Use when running fixture gen/fetch/explore, writing cone.note metadata for LLM generation, syncing between the development, test, and fixture databases, or when a fixture fails on a foreign key or unique constraint. Covers the 3-tier DB structure, dataSource strategies, fixtureGenerator, and --use-llm.
4
- ---
5
-
6
- # Fixture CLI Usage Guide
7
-
8
- Sonamu provides CLI commands for generating and managing fixture data for testing.
9
-
10
- **Note**: See the "Practical Tips" section below for fixture generation tips.
11
-
12
- ---
13
-
14
- ## Understanding the 3-Tier DB Structure (Required)
15
-
16
- Sonamu uses a three-tier database structure. **Without understanding this structure, using fixture commands will be confusing.**
17
-
18
- ```
19
- production/development master (live DB)
20
- ↓ (fixture fetch)
21
- project_fixture (fixture DB)
22
- ↓ (fixture sync)
23
- project_test (test DB)
24
- ```
25
-
26
- ### Role of Each DB
27
-
28
- | DB | Purpose | Data origin |
29
- | ----------------- | -------------------------------- | --------------------------------------- |
30
- | `project` | Production/development live DB | Real user data |
31
- | `project_fixture` | Reference data store for testing | Imported via fetch or generated via gen |
32
- | `project_test` | Test execution environment | Synced from fixture |
33
-
34
- ### Which DB Each Command Uses
35
-
36
- | Command | sourceDb | targetDb | Description |
37
- | --------------- | ----------------- | ---------- | ------------------------------------------------------ |
38
- | `fixture gen` | fixture DB | fixture DB | Resolves and generates relations within the fixture DB |
39
- | `fixture fetch` | production master | fixture DB | Imports from live DB → fixture DB |
40
- | `fixture sync` | fixture DB | test DB | Synchronizes fixture DB → test DB (existing behavior) |
41
-
42
- **CRITICAL**: Incorrect sourceDb or targetDb settings will cause FK reference errors.
43
-
44
- ---
45
-
46
- ## CLI Commands
47
-
48
- ### 1. fixture gen - Generate new fixtures
49
-
50
- Generates new test data based on faker.
51
-
52
- **CRITICAL: The `--use-llm` option must always be used in real projects.** Without `--use-llm`, domain context from cone.note is not applied and only faker defaults are used, potentially producing meaningless data. This option is required for the LLM to reference `contract/**/*.contract.md` and generate contextually appropriate data.
53
-
54
- **CRITICAL: Before running fixture gen, verify that `cone.note` exists for key props.** Without cone.note, the LLM cannot understand context and cannot generate meaningful data. If cone.note is insufficient, regenerate it with `pnpm sonamu cone generate --use-llm`.
55
-
56
- #### Basic Usage
57
-
58
- ```bash
59
- # Interactive mode (recommended)
60
- pnpm sonamu fixture gen
61
-
62
- # Specify Entity
63
- pnpm sonamu fixture gen --include User --count 10
64
-
65
- # Multiple Entities
66
- pnpm sonamu fixture gen --include User,Post,Comment --count 5
67
-
68
- # All Entities
69
- pnpm sonamu fixture gen --all --count 3
70
-
71
- # All minus exclusions
72
- pnpm sonamu fixture gen --all --exclude Admin,Log --count 3
73
- ```
74
-
75
- #### Save Options
76
-
77
- ```bash
78
- # Save to DB (default)
79
- pnpm sonamu fixture gen --include User --count 10 --save-to db
80
-
81
- # Save to file (tablename.json)
82
- pnpm sonamu fixture gen --include User --count 10 --save-to file
83
- # → test/fixtures/users.json
84
-
85
- # Specify filename
86
- pnpm sonamu fixture gen --include User --count 10 --save-to file:my-users.json
87
- # → test/fixtures/my-users.json
88
-
89
- # Output only (do not save)
90
- pnpm sonamu fixture gen --include User --count 10 --save-to none
91
- ```
92
-
93
- #### Options
94
-
95
- - `--include <entities>`: List of Entities to generate (comma-separated)
96
- - `--all`: All Entities
97
- - `--exclude <entities>`: Used with --all; Entities to exclude
98
- - `--count <number>`: Number to generate per Entity (default: 5)
99
- - `--save-to <target>`: Save mode - `db` | `file` | `file:name.json` | `none`
100
- - `--use-llm`: Enable LLM-based generation from cone.note (requires ANTHROPIC_API_KEY)
101
- - `--no-cache`: Disable LLM cache (default: cache ON)
102
- - `--llm-model <model>`: Specify LLM model (default: `claude-sonnet-4-6`)
103
-
104
- ---
105
-
106
- ### 2. fixture fetch - Import from live DB
107
-
108
- Fetches data from the production/development DB and saves it to the fixture DB.
109
-
110
- #### Basic Usage
111
-
112
- ```bash
113
- # Interactive mode
114
- pnpm sonamu fixture fetch
115
-
116
- # Fetch recent data
117
- pnpm sonamu fixture fetch --include User --strategy recent --limit 10
118
-
119
- # Multiple Entities
120
- pnpm sonamu fixture fetch --include User,Post --strategy sample --limit 5
121
-
122
- # All Entities
123
- pnpm sonamu fixture fetch --all --strategy recent --limit 3
124
- ```
125
-
126
- #### Strategies
127
-
128
- | Strategy | Description | Example |
129
- | -------- | -------------------------------- | ------------------------------ |
130
- | `recent` | Most recent data (by created_at) | `--strategy recent --limit 10` |
131
- | `sample` | Uniform sampling | `--strategy sample --limit 10` |
132
- | `random` | Random sampling | `--strategy random --limit 10` |
133
-
134
- **CRITICAL**: fetch retrieves related data **recursively** (maxDepth: 2)
135
-
136
- - Fetching User → also imports User's department and institution
137
- - Fetching Post → also imports Post's author (User)
138
-
139
- #### Options
140
-
141
- - `--include <entities>`: List of Entities to import
142
- - `--all`: All Entities
143
- - `--exclude <entities>`: Used with --all; Entities to exclude
144
- - `--strategy <strategy>`: Fetch strategy - `recent` | `sample` | `random` (default: recent)
145
- - `--limit <number>`: Number of records per Entity (default: 10)
146
-
147
- ---
148
-
149
- ### 3. fixture explore - Query data (without saving)
150
-
151
- Queries data from the live DB and prints it to the console. **Query only — nothing is saved.**
152
-
153
- #### Basic Usage
154
-
155
- ```bash
156
- # Interactive mode
157
- pnpm sonamu fixture explore
158
-
159
- # Query recent Users
160
- pnpm sonamu fixture explore --include User --strategy recent --limit 10
161
-
162
- # Sampling
163
- pnpm sonamu fixture explore --include Department --strategy sample --limit 5
164
- ```
165
-
166
- #### When to use
167
-
168
- - Quickly check what data exists in the live DB
169
- - Preview before running fixture fetch
170
- - Understand data distribution
171
-
172
- ---
173
-
174
-
175
- ## Reference Map
176
-
177
- | Need | Read |
178
- | --- | --- |
179
- | Practical scenarios, tips, cone metadata options, FixtureGenerator, troubleshooting | `references/cli-usage.md` |
180
- | Cone field types, generation priority, cone CLI, dataSource strategies | `references/cone.md` |
@@ -1,439 +0,0 @@
1
- # Fixture CLI — Scenarios, Tips, Troubleshooting
2
-
3
- ## Practical Scenarios
4
-
5
- ### Scenario 1: Starting from an empty DB
6
-
7
- ```bash
8
- # 1. Generate base fixtures
9
- pnpm sonamu fixture gen --all --exclude Admin,Log --count 5
10
-
11
- # 2. Sync fixture → test DB
12
- pnpm sonamu fixture sync
13
-
14
- # 3. Run tests
15
- pnpm test
16
- ```
17
-
18
- ### Scenario 2: Testing with real data
19
-
20
- ```bash
21
- # 1. Fetch recent data from live DB
22
- pnpm sonamu fixture fetch --include User,Department --strategy recent --limit 20
23
-
24
- # 2. Generate additional data
25
- pnpm sonamu fixture gen --include Post,Comment --count 50
26
-
27
- # 3. Sync fixture → test DB
28
- pnpm sonamu fixture sync
29
-
30
- # 4. Run tests
31
- pnpm test
32
- ```
33
-
34
- ### Scenario 3: Preparing for a specific scenario test
35
-
36
- ```bash
37
- # 1. Generate specific Entities only
38
- pnpm sonamu fixture gen --include User --count 3
39
-
40
- # 2. Generate additional interactively
41
- pnpm sonamu fixture gen
42
- # ? Select entities to generate fixtures for: choose Post, Comment
43
- # ? Count per entity: 10
44
-
45
- # 3. Save to file (for version control)
46
- pnpm sonamu fixture gen --include User --count 10 --save-to file
47
- # → creates test/fixtures/users.json
48
-
49
- # 4. fixture sync
50
- pnpm sonamu fixture sync
51
- ```
52
-
53
- ---
54
-
55
- ## Practical Tips
56
-
57
- ### 1. Automatic Korean data generation
58
-
59
- FixtureGenerator automatically generates Korean data for specific field names:
60
-
61
- **Fields with automatic Korean generation**:
62
-
63
- - `name`, `username`: Korean full name (`fakerKO.person.fullName()`)
64
- - Entity is `Department` and prop is `name`: Korean department name
65
-
66
- **Example output**:
67
-
68
- ```typescript
69
- // User
70
- { name: "김민준", username: "이서연" }
71
-
72
- // Department
73
- { name: "개발팀 1팀", name: "글로벌 마케팅팀" }
74
- ```
75
-
76
- **Customization**:
77
-
78
- ```typescript
79
- // Edit in fixture-generator.ts
80
- if (entity?.id === "Department" && prop.name === "name") {
81
- const departments = ["개발팀", "기획팀", "마케팅팀", "영업팀"];
82
- // ...
83
- }
84
- ```
85
-
86
- ### 2. Handling Unique Constraints
87
-
88
- Fields with unique constraints require a deduplication strategy.
89
-
90
- **Problem**:
91
-
92
- ```sql
93
- -- departments table
94
- UNIQUE (company_id, name)
95
- ```
96
-
97
- **Solution: Automatic variation**
98
-
99
- ```typescript
100
- // Prevents "개발팀" from being generated multiple times under the same company_id
101
- // Automatically adds prefix/suffix with 70% probability
102
-
103
- // Result:
104
- "개발팀"; // 30%
105
- "개발팀 1팀"; // 20%
106
- "개발팀 본부"; // 20%
107
- "글로벌 개발팀"; // 30%
108
- ```
109
-
110
- **Implementation location**: `generateDefaultValue()` in `fixture-generator.ts`
111
-
112
- ### 3. BelongsToOne FK Setup
113
-
114
- BelongsToOne relations auto-generate a `{name}_id` column, so code must use the `_id` suffix.
115
-
116
- **Entity definition**:
117
-
118
- ```json
119
- {
120
- "type": "relation",
121
- "name": "company",
122
- "with": "Company",
123
- "relationType": "BelongsToOne"
124
- }
125
- ```
126
-
127
- **Inside FixtureGenerator**:
128
-
129
- ```typescript
130
- // ✓ CORRECT
131
- fixture[`${prop.name}_id`] = relationValue; // company_id
132
-
133
- // ✗ WRONG
134
- fixture[prop.name] = relationValue; // company (FK saved as NULL!)
135
- ```
136
-
137
- **Easy to get wrong because**:
138
-
139
- - Entity JSON defines `name: "company"`
140
- - DB column is auto-created as `company_id`
141
- - Code must use `company_id`
142
-
143
- ### 4. Resolving Ordering Issues
144
-
145
- fixture gen **automatically sorts by dependency order** (uses FixtureManager's RelationGraph).
146
-
147
- **Example**:
148
-
149
- ```bash
150
- # Department references Company, but no need to worry about order
151
- pnpm sonamu fixture gen --include Department,Company --count 5
152
-
153
- # Internally:
154
- # 1. Company generated first (no FK)
155
- # 2. Department generated next (references company_id)
156
- ```
157
-
158
- **Note**: Circular references will produce a warning.
159
-
160
- **Internal implementation (RelationGraph):**
161
-
162
- `FixtureManager` uses the `RelationGraph` class (`_relation-graph.ts`) to build a dependency graph and topologically sort it to determine insertion order. It analyzes BelongsToOne and OneToOne (hasJoinColumn) relations to guarantee that parent entities are always inserted before children.
163
-
164
- ### 5. DB Sequence Reset
165
-
166
- After generating fixtures, ID sequences may be out of sync.
167
-
168
- **Check**:
169
-
170
- ```bash
171
- PGPASSWORD=1234 psql -h 0.0.0.0 -U postgres -d project_fixture -c "
172
- SELECT sequencename, last_value
173
- FROM pg_sequences
174
- WHERE schemaname = 'public'
175
- ORDER BY sequencename;
176
- "
177
- ```
178
-
179
- **Reset**:
180
-
181
- ```sql
182
- -- Per table
183
- SELECT setval('departments_id_seq', (SELECT MAX(id) FROM departments), true);
184
- SELECT setval('companies_id_seq', (SELECT MAX(id) FROM companies), true);
185
- ```
186
-
187
- **Automated**:
188
-
189
- ```bash
190
- # Reset all sequences script
191
- PGPASSWORD=1234 psql -h 0.0.0.0 -U postgres -d project_fixture -c "
192
- SELECT 'SELECT setval(''' || sequencename || ''', (SELECT COALESCE(MAX(id), 1) FROM ' ||
193
- replace(sequencename, '_id_seq', '') || '), true);'
194
- FROM pg_sequences
195
- WHERE schemaname = 'public' AND sequencename LIKE '%_id_seq';
196
- " | grep SELECT | PGPASSWORD=1234 psql -h 0.0.0.0 -U postgres -d project_fixture
197
- ```
198
-
199
- ### 6. Using File Storage
200
-
201
- Saving to file enables **version control**.
202
-
203
- ```bash
204
- # 1. Save to file
205
- pnpm sonamu fixture gen --include User --count 10 --save-to file
206
- # → test/fixtures/users.json
207
-
208
- # 2. Commit to git
209
- git add test/fixtures/users.json
210
- git commit -m "Add user fixtures for testing"
211
-
212
- # 3. Other developers can test with the same data
213
- ```
214
-
215
- **When to use**:
216
-
217
- - Consistent test data needed in CI/CD environments
218
- - Reproducing specific scenarios
219
- - Sharing test data across team members
220
-
221
- ---
222
-
223
- ## Advanced: cone Metadata (Optional)
224
-
225
- Adding `cone` metadata to Entity JSON gives you finer control over fixture generation.
226
-
227
- ### dataSource - Specify a reference strategy
228
-
229
- ```json
230
- {
231
- "name": "Post",
232
- "props": [
233
- {
234
- "name": "author",
235
- "type": "relation",
236
- "with": "User",
237
- "relationType": "BelongsToOne",
238
- "cone": {
239
- "dataSource": {
240
- "strategy": "recent",
241
- "config": { "limit": 5 }
242
- }
243
- }
244
- }
245
- ]
246
- }
247
- ```
248
-
249
- **Supported strategies**:
250
-
251
- - `sample`: Uniform sampling
252
- - `recent`: Most recent data (by created_at)
253
- - `random`: Random sampling
254
- - `ids`: Specific IDs
255
- - `query`: Custom query
256
- - `file`: Load from file
257
-
258
- ### fixtureGenerator - Custom generation logic
259
-
260
- ```json
261
- {
262
- "name": "email",
263
- "type": "string",
264
- "cone": {
265
- "fixtureGenerator": "faker.internet.email()"
266
- }
267
- }
268
- ```
269
-
270
- **Security note**: Security risk due to eval usage (only use trusted expressions)
271
-
272
- ### fixtureDefault - Specify a default value
273
-
274
- ```json
275
- {
276
- "name": "status",
277
- "type": "string",
278
- "cone": {
279
- "fixtureDefault": "active"
280
- }
281
- }
282
- ```
283
-
284
- ### note - Description and LLM trigger
285
-
286
- ```json
287
- {
288
- "name": "phone",
289
- "type": "string",
290
- "cone": {
291
- "note": "Korean phone number in 010-XXXX-XXXX format"
292
- }
293
- }
294
- ```
295
-
296
- **How it works**:
297
-
298
- - Without `--use-llm`: serves only as a reference description for developers/LLMs (used by cone-generator when generating metadata)
299
- - With `--use-llm`: fixture gen calls the Claude API and generates actual values based on the note content
300
-
301
- **Use cases**:
302
-
303
- - Contextual text that is hard to express with simple faker.js (self-introductions, descriptions, etc.)
304
- - Explaining the field's meaning and generation pattern to developers
305
- - No length limit (short patterns or long descriptions are both fine)
306
-
307
- ---
308
-
309
- ### LLM-based Data Generation
310
-
311
- When the `--use-llm` flag is used, `cone.note` acts as the trigger for Claude API calls.
312
-
313
- #### Priority chain
314
-
315
- ```
316
- 1. override value (passed at generate() call time)
317
- 2. cone.note + LLM ← activated with --use-llm flag (highest priority when API key is present)
318
- 3. fixtureGenerator (faker.js expression) ← fallback when LLM fails
319
- 4. fixtureDefault (fixed default value)
320
- 5. type-based default (auto-generated)
321
- ```
322
-
323
- #### CLI usage
324
-
325
- ```bash
326
- # Enable LLM
327
- pnpm sonamu fixture gen --include User --count 10 --use-llm
328
-
329
- # Disable cache
330
- pnpm sonamu fixture gen --include User --count 10 --use-llm --no-cache
331
- ```
332
-
333
- #### API Key Setup
334
-
335
- ```bash
336
- # Option 1: environment variable
337
- export ANTHROPIC_API_KEY=sk-ant-...
338
-
339
- # Option 2: sonamu.config.ts
340
- export default defineConfig({
341
- secret: { anthropic_api_key: "sk-ant-..." }
342
- });
343
- ```
344
-
345
- #### Caching behavior
346
-
347
- - When `useLLM=true`, all LLM-targeted fields in a single row are generated in **a single LLM call** (not per-field individual calls)
348
- - This single call guarantees automatic consistency across correlated fields such as `name`, `name_en`, `name_cn`, `email`
349
- - Generated results are stored in an in-memory cache keyed by `rowKey:fieldName`, and returned immediately for subsequent fields in the same row
350
- - Cache is valid only within the same FixtureGenerator instance
351
- - Cache can be disabled with `--no-cache` (the row-level generation approach itself is preserved)
352
-
353
- #### Fallback behavior
354
-
355
- - No API key → falls back to fixtureDefault or type default (no error)
356
- - LLM call fails → same fallback (console warning only)
357
-
358
- #### When to choose note vs fixtureGenerator
359
-
360
- | Situation | Recommended |
361
- | ---------------------------------------------------------- | --------------------------------- |
362
- | Simple values such as email, name, number | `fixtureGenerator` (faker.js) |
363
- | Contextual text such as self-introductions or descriptions | `cone.note` + `--use-llm` (LLM) |
364
- | Selecting from a specific list of values | `fixtureGenerator` (arrayElement) |
365
-
366
- ---
367
-
368
- ## FixtureGenerator Options (FixtureGeneratorOptions)
369
-
370
- **Source:** `modules/sonamu/src/testing/fixture-generator.ts`
371
-
372
- | Option | Type | Default | Description |
373
- | ---------------- | -------------------------- | --------------------- | --------------------------------------------- |
374
- | `locale` | `"ko"` \| `"en"` \| `"ja"` | `"ko"` | Locale for generated data |
375
- | `useLLM` | boolean | `false` | LLM-based data generation (`--use-llm`) |
376
- | `enableLLMCache` | boolean | `true` | Cache LLM results (disable with `--no-cache`) |
377
- | `llmModel` | string | `"claude-sonnet-4-6"` | LLM model to use |
378
-
379
- ---
380
-
381
- ## Troubleshooting
382
-
383
- ### Problem 1: "Cannot generate non-nullable relation without dataSource"
384
-
385
- **Cause**: BelongsToOne relation is non-nullable but there is no data to reference
386
-
387
- **Solution**:
388
-
389
- ```bash
390
- # Generate the referenced Entity first
391
- pnpm sonamu fixture gen --include Company --count 5
392
-
393
- # Then generate Department
394
- pnpm sonamu fixture gen --include Department --count 10
395
- ```
396
-
397
- Or:
398
-
399
- ```bash
400
- # Generate together (auto-sorted by dependency order)
401
- pnpm sonamu fixture gen --include Company,Department --count 5
402
- ```
403
-
404
- ### Problem 2: "duplicate key value violates unique constraint"
405
-
406
- **Cause**: Duplicate values generated for a field with a unique constraint
407
-
408
- **Solution**:
409
-
410
- 1. Modify the per-field generation logic for that Entity in `fixture-generator.ts`
411
- 2. Add prefix/suffix or use UUID
412
- 3. Reduce count
413
-
414
- ### Problem 3: FK reference error "violates foreign key constraint"
415
-
416
- **Cause**: Incorrect sourceDb/targetDb configuration
417
-
418
- **Check**:
419
-
420
- ```typescript
421
- // Verify in fixture.ts
422
- const fixtureDb = createKnexInstance(Sonamu.dbConfig.fixture);
423
- const generator = new FixtureGenerator(fixtureDb, fixtureDb, "fixture", EntityManager);
424
- ```
425
-
426
- **Correct configuration**:
427
-
428
- - `fixture gen`: sourceDb = fixtureDb, targetDb = fixtureDb
429
- - `fixture fetch`: sourceDb = production, targetDb = fixtureDb
430
-
431
- ---
432
-
433
- ## References
434
-
435
- - **3-Tier DB Structure**: "3-Tier DB Structure" section in `sonamu-config`
436
- - **Fixture generation tips**: "Fixture Data Creation Tips" section in `sonamu-testing`
437
- - **BelongsToOne FK**: "Using FK in Code" section in `sonamu-entity`
438
- - **Implementation**: `modules/sonamu/src/bin/fixture.ts`
439
- - **Generation logic**: `modules/sonamu/src/testing/fixture-generator.ts`