You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
5.**generator.ts** - Main generator that orchestrates the process and handles file I/O
35
36
36
37
### Key Components
37
38
@@ -40,37 +41,48 @@ The codebase follows a clear separation of concerns with four main modules:
40
41
- Filters only scalar and enum fields (ignores relations)
41
42
- Maps Prisma names to database names using `@@map` directives
42
43
44
+
**config.ts** (`src/config.ts`):
45
+
- Defines the `Config` interface for all configuration options
46
+
- Implements `readConfig` function to extract and validate configuration from GeneratorOptions
47
+
- Handles parsing of targets, patterns, provider detection, and output directory resolution
48
+
- Centralizes all configuration logic for better maintainability
49
+
43
50
**comment.ts** (`src/comment.ts`):
44
-
- Creates comment structures for tables and columns based on targets
51
+
- Creates comment structures for tables and columns based on configuration
45
52
- Implements diffing logic to generate only changed comments
46
-
-Handles filtering via `ignorePattern` and `ignoreCommentPattern`
53
+
-Accepts `Config` object instead of individual parameters for cleaner interface
47
54
- Supports enum information injection into field comments
48
55
49
56
**statement.ts** (`src/statement.ts`):
50
-
- Generates PostgreSQL `COMMENT ON TABLE` and `COMMENT ON COLUMN` statements
57
+
- Generates PostgreSQL and MySQL `COMMENT ON` statements
51
58
- Handles comment escaping and multi-line comments with E-strings
52
-
- Supports schema-qualified table names
59
+
- Supports schema-qualified table names and multiple database providers
53
60
54
61
**generator.ts** (`src/generator.ts`):
55
62
- Entry point that implements Prisma's generator interface
63
+
- Uses `readConfig` to obtain all configuration settings
56
64
- Manages state persistence via `comments-latest.json`
57
65
- Creates migration files with timestamped directories
58
-
- Orchestrates the entire generation process
66
+
- Orchestrates the entire generation process with improved separation of concerns
59
67
60
68
### State Management
61
69
The generator maintains state between runs by storing the current comments in `prisma/migrations/comments-latest.json`. This enables differential generation - only creating migration files for changed comments.
62
70
63
71
### Configuration Options
72
+
All configuration options are now centralized in `config.ts`:
64
73
-`targets` - Select "table", "column", or both for comment generation
65
74
-`ignorePattern` - Regex to exclude models by database name
66
75
-`ignoreCommentPattern` - Regex to exclude comments by content
67
76
-`includeEnumInFieldComment` - Add enum values to field comments
77
+
-`provider` - Auto-detected database provider (PostgreSQL or MySQL)
78
+
-`outputDir` - Parsed output directory from generator configuration
68
79
69
80
## Testing
70
81
71
82
Tests use Vitest and are organized as:
72
-
- Unit tests for each module (e.g., `comment.test.ts`)
83
+
- Unit tests for each module (e.g., `comment.test.ts`, `config.test.ts`)
73
84
- Integration tests for the generator (`generator.test.ts`)
85
+
- Configuration testing with comprehensive coverage (`config.test.ts` - 17 test cases)
74
86
- Snapshot testing for generated SQL output
75
87
- Test fixtures in `src/__fixtures__/` with various schema scenarios
Copy file name to clipboardExpand all lines: README.md
+17-1Lines changed: 17 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -240,8 +240,24 @@ COMMENT ON COLUMN "products"."type" IS E'Product Type\nenum: enum_product_type(B
240
240
## Supported Databases
241
241
242
242
- PostgreSQL
243
+
- MySQL (Experimental)
243
244
244
-
Other databases may be available, but the above is the only one checked.
245
+
### MySQL Support (Experimental)
246
+
247
+
MySQL support is currently experimental and we are seeking feedback. For MySQL, this generator uses stored procedures to manage column comments due to MySQL's specific syntax requirements for column comment updates.
248
+
249
+
**Why Stored Procedures are Used:**
250
+
MySQL requires the full column definition when updating column comments via `ALTER TABLE ... MODIFY COLUMN`. To handle this complexity, the generator creates a stored procedure (`prisma_update_column_comment`) that dynamically retrieves the current column definition from `information_schema` and safely applies the comment update.
251
+
252
+
**Required MySQL Permissions:**
253
+
-`CREATE ROUTINE` - Required to create stored procedures for column comments
254
+
-`ALTER ROUTINE` - Required to modify stored procedures if needed
255
+
256
+
The generated SQL includes:
257
+
- Direct `ALTER TABLE` statements for table comments
258
+
- Stored procedures for column comment updates (automatically created and cleaned up)
259
+
260
+
Other databases may be available, but the above are the only ones tested.
0 commit comments