sqlew 4.0.0 → 4.0.2

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 (92) hide show
  1. package/CHANGELOG.md +126 -0
  2. package/README.md +12 -8
  3. package/dist/cli/db-dump.d.ts +4 -0
  4. package/dist/cli/db-dump.d.ts.map +1 -1
  5. package/dist/cli/db-dump.js +89 -114
  6. package/dist/cli/db-dump.js.map +1 -1
  7. package/dist/cli/db-export.d.ts +1 -0
  8. package/dist/cli/db-export.d.ts.map +1 -1
  9. package/dist/cli/db-export.js +46 -80
  10. package/dist/cli/db-export.js.map +1 -1
  11. package/dist/cli/db-import.d.ts +1 -0
  12. package/dist/cli/db-import.d.ts.map +1 -1
  13. package/dist/cli/db-import.js +52 -90
  14. package/dist/cli/db-import.js.map +1 -1
  15. package/dist/cli.d.ts +10 -1
  16. package/dist/cli.d.ts.map +1 -1
  17. package/dist/cli.js +57 -59
  18. package/dist/cli.js.map +1 -1
  19. package/dist/database/migrations/v4/20251127000002_v4_seed_help_system.d.ts.map +1 -1
  20. package/dist/database/migrations/v4/20251127000002_v4_seed_help_system.js +7 -4
  21. package/dist/database/migrations/v4/20251127000002_v4_seed_help_system.js.map +1 -1
  22. package/dist/database/migrations/v4/20251128000000_drop_all_views.d.ts +24 -0
  23. package/dist/database/migrations/v4/20251128000000_drop_all_views.d.ts.map +1 -0
  24. package/dist/database/migrations/v4/20251128000000_drop_all_views.js +67 -0
  25. package/dist/database/migrations/v4/20251128000000_drop_all_views.js.map +1 -0
  26. package/dist/database/operations/inserts.d.ts.map +1 -1
  27. package/dist/database/operations/inserts.js +7 -0
  28. package/dist/database/operations/inserts.js.map +1 -1
  29. package/dist/index.d.ts +4 -0
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +70 -48
  32. package/dist/index.js.map +1 -1
  33. package/dist/tests/database/testing-config.d.ts +4 -0
  34. package/dist/tests/database/testing-config.d.ts.map +1 -1
  35. package/dist/tests/database/testing-config.js +1 -1
  36. package/dist/tests/database/testing-config.js.map +1 -1
  37. package/dist/tests/docker/native/test-harness.d.ts +56 -1
  38. package/dist/tests/docker/native/test-harness.d.ts.map +1 -1
  39. package/dist/tests/docker/native/test-harness.js +221 -5
  40. package/dist/tests/docker/native/test-harness.js.map +1 -1
  41. package/dist/tests/feature/vcs/git-aware-completion.test.js +33 -0
  42. package/dist/tests/feature/vcs/git-aware-completion.test.js.map +1 -1
  43. package/dist/tests/unit/utils/case-insensitive-validator.test.d.ts +2 -0
  44. package/dist/tests/unit/utils/case-insensitive-validator.test.d.ts.map +1 -0
  45. package/dist/tests/unit/utils/case-insensitive-validator.test.js +97 -0
  46. package/dist/tests/unit/utils/case-insensitive-validator.test.js.map +1 -0
  47. package/dist/tools/constraints/actions/get.d.ts +2 -2
  48. package/dist/tools/constraints/actions/get.d.ts.map +1 -1
  49. package/dist/tools/constraints/actions/get.js +56 -19
  50. package/dist/tools/constraints/actions/get.js.map +1 -1
  51. package/dist/tools/context/actions/create-policy.d.ts.map +1 -1
  52. package/dist/tools/context/actions/create-policy.js +5 -1
  53. package/dist/tools/context/actions/create-policy.js.map +1 -1
  54. package/dist/tools/files/actions/get.d.ts +2 -2
  55. package/dist/tools/files/actions/get.d.ts.map +1 -1
  56. package/dist/tools/files/actions/get.js +22 -51
  57. package/dist/tools/files/actions/get.js.map +1 -1
  58. package/dist/types.d.ts +10 -6
  59. package/dist/types.d.ts.map +1 -1
  60. package/dist/utils/case-insensitive-validator.d.ts +102 -0
  61. package/dist/utils/case-insensitive-validator.d.ts.map +1 -0
  62. package/dist/utils/case-insensitive-validator.js +144 -0
  63. package/dist/utils/case-insensitive-validator.js.map +1 -0
  64. package/dist/utils/exporter/export.d.ts +22 -7
  65. package/dist/utils/exporter/export.d.ts.map +1 -1
  66. package/dist/utils/exporter/export.js +33 -49
  67. package/dist/utils/exporter/export.js.map +1 -1
  68. package/dist/utils/importer/import.js +64 -27
  69. package/dist/utils/importer/import.js.map +1 -1
  70. package/dist/utils/importer/master-tables.d.ts +3 -1
  71. package/dist/utils/importer/master-tables.d.ts.map +1 -1
  72. package/dist/utils/importer/master-tables.js +7 -29
  73. package/dist/utils/importer/master-tables.js.map +1 -1
  74. package/dist/utils/sql-dump/core/generate-dump.d.ts.map +1 -1
  75. package/dist/utils/sql-dump/core/generate-dump.js +25 -5
  76. package/dist/utils/sql-dump/core/generate-dump.js.map +1 -1
  77. package/dist/utils/sql-dump/core/index-export.d.ts +3 -2
  78. package/dist/utils/sql-dump/core/index-export.d.ts.map +1 -1
  79. package/dist/utils/sql-dump/core/index-export.js +9 -9
  80. package/dist/utils/sql-dump/core/index-export.js.map +1 -1
  81. package/dist/utils/sql-dump/schema/indexes.d.ts +14 -0
  82. package/dist/utils/sql-dump/schema/indexes.d.ts.map +1 -1
  83. package/dist/utils/sql-dump/schema/indexes.js +81 -15
  84. package/dist/utils/sql-dump/schema/indexes.js.map +1 -1
  85. package/dist/utils/sql-dump/schema/tables.d.ts +4 -1
  86. package/dist/utils/sql-dump/schema/tables.d.ts.map +1 -1
  87. package/dist/utils/sql-dump/schema/tables.js +81 -51
  88. package/dist/utils/sql-dump/schema/tables.js.map +1 -1
  89. package/docs/cli/DATABASE_MIGRATION.md +62 -58
  90. package/docs/cli/DATA_EXPORT_IMPORT.md +403 -103
  91. package/docs/cli/README.md +95 -45
  92. package/package.json +4 -6
@@ -2,6 +2,14 @@
2
2
 
3
3
  > JSON-based project data migration for sharing and multi-database workflows
4
4
 
5
+ ## 📢 v4.0.2 Update: JSON is Now Required for Cross-Database Migration
6
+
7
+ Starting from v4.0.2, **JSON export/import is the ONLY supported method for cross-database migrations** (e.g., SQLite → MySQL, MySQL → PostgreSQL).
8
+
9
+ SQL dump (`db:dump`) no longer supports cross-database format conversion. See [Complete Cross-Database Migration Guide](#complete-cross-database-migration-guide-v402) below for step-by-step instructions.
10
+
11
+ ---
12
+
5
13
  ## Overview
6
14
 
7
15
  sqlew provides a complete JSON export/import system for migrating project data between databases. This is useful for:
@@ -21,35 +29,27 @@ solutions including schema + data using SQL dumps.
21
29
  ### Export a Project
22
30
 
23
31
  ```bash
24
- # You have to install sqlew via npm to use CLI mode
25
- cd /path/to/your/project
26
- npm install sqlew
32
+ # Export all projects (no installation required!)
33
+ npx sqlew db:export backup.json
27
34
 
28
- # Export all projects
29
- node node_modules/sqlew/dist/cli.js db:export --output=full-backup.json
30
-
31
- # or Export specific project to file
32
- node node_modules/sqlew/dist/cli.js db:export --project=my-project --output=backup.json
35
+ # Export specific project to file
36
+ npx sqlew db:export backup.json project=my-project
33
37
 
34
38
  # Export to stdout (pipe to another command)
35
- node node_modules/sqlew/dist/cli.js db:export --project=visualizer
39
+ npx sqlew db:export project=visualizer
36
40
  ```
37
41
 
38
42
  ### Import a Project
39
43
 
40
44
  ```bash
41
- # You have to install sqlew via npm to use CLI mode (We recommend install per project)
42
- cd /path/to/your/other-project
43
- npm install sqlew
44
-
45
45
  # Import from JSON export
46
- node node_modules/sqlew/dist/cli.js db:import --source=backup.json
46
+ npx sqlew db:import backup.json
47
47
 
48
48
  # Import with custom project name
49
- node node_modules/sqlew/dist/cli.js db:import --source=backup.json --project-name=new-name
49
+ npx sqlew db:import backup.json project-name=new-name
50
50
 
51
51
  # Dry-run validation (no actual import)
52
- node node_modules/sqlew/dist/cli.js db:import --source=backup.json --dry-run
52
+ npx sqlew db:import backup.json dry-run=true
53
53
  ```
54
54
 
55
55
  ## Export Command
@@ -57,17 +57,16 @@ node node_modules/sqlew/dist/cli.js db:import --source=backup.json --dry-run
57
57
  ### Syntax
58
58
 
59
59
  ```bash
60
- node node_modules/sqlew/dist/cli.js db:export [options]
60
+ npx sqlew db:export [output-file] [key=value ...]
61
61
  ```
62
62
 
63
63
  ### Options
64
64
 
65
- | Option | Description | Default |
66
- |--------------------|---------------------------------|-------------------|
67
- | `--project <name>` | Export specific project by name | All projects |
68
- | `--output <file>` | Output file path | stdout |
69
- | `--db-path <path>` | Database file path | `.sqlew/sqlew.db` |
70
- | `--config <path>` | Config file path | Auto-detect |
65
+ | Option | Description | Default |
66
+ |-------------------|---------------------------------|-------------------|
67
+ | `project=<name>` | Export specific project by name | All projects |
68
+ | `db-path=<path>` | Database file path | `.sqlew/sqlew.db` |
69
+ | `config=<path>` | Config file path | Auto-detect |
71
70
 
72
71
  ### What Gets Exported
73
72
 
@@ -96,19 +95,19 @@ node node_modules/sqlew/dist/cli.js db:export [options]
96
95
  ### Syntax
97
96
 
98
97
  ```bash
99
- node node_modules/sqlew/dist/cli.js db:import --source=<file> [options]
98
+ npx sqlew db:import <source-file> [key=value ...]
100
99
  ```
101
100
 
102
101
  ### Options
103
102
 
104
- | Option | Description | Default |
105
- |-------------------------|-------------------------------|--------------------|
106
- | `--source <file>` | JSON export file path | **Required** |
107
- | `--project-name <name>` | Target project name | Use name from JSON |
108
- | `--skip-if-exists` | Skip import if project exists | `true` |
109
- | `--dry-run` | Validate only, don't import | `false` |
110
- | `--db-path <path>` | Database file path | `.sqlew/sqlew.db` |
111
- | `--config <path>` | Config file path | Auto-detect |
103
+ | Option | Description | Default |
104
+ |--------------------------|-------------------------------|--------------------|
105
+ | `<source-file>` | JSON export file path | **Required** |
106
+ | `project-name=<name>` | Target project name | Use name from JSON |
107
+ | `skip-if-exists=true` | Skip import if project exists | `true` |
108
+ | `dry-run=true` | Validate only, don't import | `false` |
109
+ | `db-path=<path>` | Database file path | `.sqlew/sqlew.db` |
110
+ | `config=<path>` | Config file path | Auto-detect |
112
111
 
113
112
  ### Import Process
114
113
 
@@ -147,34 +146,24 @@ node node_modules/sqlew/dist/cli.js db:import --source=<file> [options]
147
146
  - Idempotent operations (safe to retry on failure)
148
147
  - Comprehensive error messages with validation details
149
148
 
150
- ## Installation for CLI Usage
149
+ ## CLI Usage
151
150
 
152
- For users who need to use export/import commands, install sqlew per-project:
151
+ **No installation required!** The unified entry point allows direct use via npx:
153
152
 
154
153
  ```bash
155
- # Install in your project directory
156
- cd /path/to/your/project
157
- npm install sqlew
158
-
159
- # Now you can use CLI commands
160
- node node_modules/sqlew/dist/cli.js db:export --output=backup.json
161
- node node_modules/sqlew/dist/cli.js db:import --source=backup.json
162
- ```
154
+ # Export data
155
+ npx sqlew db:export backup.json
163
156
 
164
- **Tip**: Add a shortcut to your `package.json` for convenience:
157
+ # Import data
158
+ npx sqlew db:import backup.json
165
159
 
166
- ```json
167
- {
168
- "scripts": {
169
- "sqlew": "node node_modules/sqlew/dist/cli.js"
170
- }
171
- }
160
+ # SQL dump (same-database backup)
161
+ npx sqlew db:dump sqlite backup.sql
172
162
  ```
173
163
 
174
- Then you can use: `npm run sqlew db:export --output=backup.json`
175
-
176
- **Note**: The MCP server (`npx sqlew`) and CLI commands are both included in the same `sqlew` package. You only need to
177
- install once.
164
+ **Note**: Both MCP server mode and CLI commands use the same `sqlew` entry point. The first argument determines the mode:
165
+ - `db:export`, `db:import`, `db:dump`, `query` → CLI mode
166
+ - No argument or MCP-related args MCP server mode
178
167
 
179
168
  ## Use Cases
180
169
 
@@ -188,20 +177,16 @@ consolidate all project contexts into one shared database.
188
177
  ```bash
189
178
  # Step 1: Export from each project's SQLite database
190
179
  cd ~/project-a
191
- npm install sqlew
192
- node node_modules/sqlew/dist/cli.js db:export --project=project-a --output=/tmp/project-a.json
180
+ npx sqlew db:export /tmp/project-a.json project=project-a
193
181
 
194
182
  cd ~/project-b
195
- npm install sqlew
196
- node node_modules/sqlew/dist/cli.js db:export --project=project-b --output=/tmp/project-b.json
183
+ npx sqlew db:export /tmp/project-b.json project=project-b
197
184
 
198
185
  cd ~/project-c
199
- npm install sqlew
200
- node node_modules/sqlew/dist/cli.js db:export --project=project-c --output=/tmp/project-c.json
186
+ npx sqlew db:export /tmp/project-c.json project=project-c
201
187
 
202
188
  # Step 2: Create shared database and import all projects
203
189
  cd ~/shared-database
204
- npm install sqlew
205
190
 
206
191
  # Configure to use single MySQL database (edit .sqlew/config.toml)
207
192
  # [database]
@@ -212,9 +197,9 @@ npm install sqlew
212
197
  # password = "mypassword"
213
198
  # database = "shared_sqlew_db"
214
199
 
215
- node node_modules/sqlew/dist/cli.js db:import --source=/tmp/project-a.json
216
- node node_modules/sqlew/dist/cli.js db:import --source=/tmp/project-b.json
217
- node node_modules/sqlew/dist/cli.js db:import --source=/tmp/project-c.json
200
+ npx sqlew db:import /tmp/project-a.json
201
+ npx sqlew db:import /tmp/project-b.json
202
+ npx sqlew db:import /tmp/project-c.json
218
203
 
219
204
  # Step 3: Configure each project to use shared database
220
205
  # In each project's .mcp.json:
@@ -245,11 +230,11 @@ node node_modules/sqlew/dist/cli.js db:import --source=/tmp/project-c.json
245
230
 
246
231
  ```bash
247
232
  # Export from source database
248
- node node_modules/sqlew/dist/cli.js db:export --project=main --output=main-export.json
233
+ npx sqlew db:export main-export.json project=main
249
234
 
250
235
  # Import to different database (different machine or different database type)
251
236
  # This works because the project doesn't exist in the target database yet
252
- node node_modules/sqlew/dist/cli.js db:import --source=main-export.json --db-path=/path/to/new/database.db
237
+ npx sqlew db:import main-export.json db-path=/path/to/new/database.db
253
238
  ```
254
239
 
255
240
  **Note**: Import skips if project name exists.
@@ -258,45 +243,361 @@ node node_modules/sqlew/dist/cli.js db:import --source=main-export.json --db-pat
258
243
 
259
244
  ```bash
260
245
  # Backup with SQL dump (preserves schema + data)
261
- node node_modules/sqlew/dist/cli.js db:dump --format=sqlite --output=backup-$(date +%Y%m%d).sql
246
+ npx sqlew db:dump sqlite backup-$(date +%Y%m%d).sql
262
247
 
263
248
  # Or simple SQLite file copy
264
249
  cp .sqlew/sqlew.db .sqlew/backup-$(date +%Y%m%d).db
265
250
  ```
266
251
 
267
- See `node node_modules/sqlew/dist/cli.js db:dump --help` for full backup options.
252
+ See `npx sqlew db:dump --help` for full backup options.
268
253
 
269
254
  ### Project Sharing
270
255
 
271
256
  ```bash
272
257
  # Developer A: Export project
273
- node node_modules/sqlew/dist/cli.js db:export --project=feature-x --output=feature-x.json
258
+ npx sqlew db:export feature-x.json project=feature-x
274
259
 
275
260
  # Developer B: Import project
276
- node node_modules/sqlew/dist/cli.js db:import --source=feature-x.json
261
+ npx sqlew db:import feature-x.json
277
262
  ```
278
263
 
279
264
  ### Multi-Project Consolidation
280
265
 
281
266
  ```bash
282
267
  # Export from different databases
283
- node node_modules/sqlew/dist/cli.js db:export --project=visualizer --output=vis.json
284
- node node_modules/sqlew/dist/cli.js db:export --project=api --output=api.json
268
+ npx sqlew db:export vis.json project=visualizer
269
+ npx sqlew db:export api.json project=api
285
270
 
286
271
  # Import to single database
287
- node node_modules/sqlew/dist/cli.js db:import --source=vis.json
288
- node node_modules/sqlew/dist/cli.js db:import --source=api.json
272
+ npx sqlew db:import vis.json
273
+ npx sqlew db:import api.json
289
274
  ```
290
275
 
291
276
  ### Cross-Database Migration
292
277
 
293
278
  ```bash
294
279
  # Export from SQLite
295
- node node_modules/sqlew/dist/cli.js db:export --output=data.json --db-path=.sqlew/sqlew.db
280
+ npx sqlew db:export data.json db-path=.sqlew/sqlew.db
281
+
282
+ # Import to MySQL (configure .sqlew/config.toml for MySQL first)
283
+ npx sqlew db:import data.json
284
+ ```
285
+
286
+ ---
287
+
288
+ ## Complete Cross-Database Migration Guide (v4.0.2+)
289
+
290
+ This section provides step-by-step instructions for migrating your sqlew database between different database systems.
291
+
292
+ ### Pre-Migration Checklist
293
+
294
+ Before starting a migration, ensure you have:
295
+
296
+ - [ ] **Backup your current database** (copy `.sqlew/sqlew.db` or use `db:dump`)
297
+ - [ ] **Note your current sqlew version** (`npm list sqlew`)
298
+ - [ ] **Target database is created and accessible**
299
+ - [ ] **Database credentials are available**
300
+ - [ ] **Required privileges**: SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, INDEX, DROP, REFERENCES
301
+
302
+ ### Migration: SQLite → MySQL
303
+
304
+ #### Step 1: Export from SQLite
305
+
306
+ ```bash
307
+ cd /path/to/your/project
308
+
309
+ # Export all data to JSON
310
+ npx sqlew db:export migration-backup.json
311
+ ```
312
+
313
+ #### Step 2: Prepare MySQL Database
314
+
315
+ ```sql
316
+ -- Connect to MySQL as admin
317
+ mysql -u root -p
318
+
319
+ -- Create database (UTF-8 required for proper text handling)
320
+ CREATE DATABASE sqlew_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
321
+
322
+ -- Create user with required privileges
323
+ CREATE USER 'sqlew_user'@'localhost' IDENTIFIED BY 'your-secure-password';
324
+ GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, INDEX, DROP, REFERENCES
325
+ ON sqlew_db.* TO 'sqlew_user'@'localhost';
326
+ FLUSH PRIVILEGES;
327
+ ```
328
+
329
+ #### Step 3: Configure config.toml for MySQL
330
+
331
+ Create or edit `.sqlew/config.toml`:
332
+
333
+ ```toml
334
+ [database]
335
+ type = "mysql"
336
+
337
+ [database.connection]
338
+ host = "localhost"
339
+ port = 3306
340
+ database = "sqlew_db"
341
+
342
+ [database.auth]
343
+ type = "direct"
344
+ user = "sqlew_user"
345
+ password = "your-secure-password"
346
+
347
+ [project]
348
+ name = "your-project-name"
349
+ ```
350
+
351
+ #### Step 4: Import to MySQL
352
+
353
+ ```bash
354
+ # Import data to MySQL (config.toml will be used automatically)
355
+ npx sqlew db:import migration-backup.json
356
+ ```
357
+
358
+ #### Step 5: Verify Migration
359
+
360
+ ```bash
361
+ # Test MCP server connection
362
+ npx sqlew --config-path=.sqlew/config.toml
363
+
364
+ # Or test with MCP Inspector
365
+ npx @modelcontextprotocol/inspector npx sqlew
366
+ ```
367
+
368
+ ---
369
+
370
+ ### Migration: SQLite → PostgreSQL
371
+
372
+ #### Step 1: Export from SQLite
373
+
374
+ ```bash
375
+ cd /path/to/your/project
376
+
377
+ # Export all data to JSON
378
+ npx sqlew db:export migration-backup.json
379
+ ```
380
+
381
+ #### Step 2: Prepare PostgreSQL Database
382
+
383
+ ```sql
384
+ -- Connect to PostgreSQL as admin
385
+ psql -U postgres
386
+
387
+ -- Create database
388
+ CREATE DATABASE sqlew_db WITH ENCODING 'UTF8';
389
+
390
+ -- Create user with required privileges
391
+ CREATE USER sqlew_user WITH PASSWORD 'your-secure-password';
392
+ GRANT ALL PRIVILEGES ON DATABASE sqlew_db TO sqlew_user;
393
+
394
+ -- Connect to the new database and grant schema privileges
395
+ \c sqlew_db
396
+ GRANT ALL ON SCHEMA public TO sqlew_user;
397
+ ```
398
+
399
+ #### Step 3: Configure config.toml for PostgreSQL
400
+
401
+ Create or edit `.sqlew/config.toml`:
402
+
403
+ ```toml
404
+ [database]
405
+ type = "postgres"
406
+
407
+ [database.connection]
408
+ host = "localhost"
409
+ port = 5432
410
+ database = "sqlew_db"
411
+
412
+ [database.auth]
413
+ type = "direct"
414
+ user = "sqlew_user"
415
+ password = "your-secure-password"
416
+
417
+ [project]
418
+ name = "your-project-name"
419
+ ```
420
+
421
+ #### Step 4: Import to PostgreSQL
422
+
423
+ ```bash
424
+ # Import data to PostgreSQL
425
+ npx sqlew db:import migration-backup.json
426
+ ```
427
+
428
+ #### Step 5: Verify Migration
429
+
430
+ ```bash
431
+ # Test MCP server connection
432
+ npx sqlew --config-path=.sqlew/config.toml
433
+ ```
434
+
435
+ ---
436
+
437
+ ### Migration: MySQL → PostgreSQL
438
+
439
+ #### Step 1: Export from MySQL
440
+
441
+ First, configure config.toml to connect to MySQL:
442
+
443
+ ```toml
444
+ [database]
445
+ type = "mysql"
446
+
447
+ [database.connection]
448
+ host = "localhost"
449
+ port = 3306
450
+ database = "sqlew_db"
451
+
452
+ [database.auth]
453
+ type = "direct"
454
+ user = "sqlew_user"
455
+ password = "mysql-password"
456
+ ```
457
+
458
+ Then export:
459
+
460
+ ```bash
461
+ npx sqlew db:export migration-backup.json
462
+ ```
463
+
464
+ #### Step 2: Prepare PostgreSQL Database
465
+
466
+ ```sql
467
+ -- Connect to PostgreSQL as admin
468
+ psql -U postgres
469
+
470
+ -- Create database
471
+ CREATE DATABASE sqlew_db WITH ENCODING 'UTF8';
472
+
473
+ -- Create user
474
+ CREATE USER sqlew_user WITH PASSWORD 'postgres-password';
475
+ GRANT ALL PRIVILEGES ON DATABASE sqlew_db TO sqlew_user;
476
+ \c sqlew_db
477
+ GRANT ALL ON SCHEMA public TO sqlew_user;
478
+ ```
479
+
480
+ #### Step 3: Update config.toml for PostgreSQL
481
+
482
+ ```toml
483
+ [database]
484
+ type = "postgres"
485
+
486
+ [database.connection]
487
+ host = "localhost"
488
+ port = 5432
489
+ database = "sqlew_db"
490
+
491
+ [database.auth]
492
+ type = "direct"
493
+ user = "sqlew_user"
494
+ password = "postgres-password"
495
+
496
+ [project]
497
+ name = "your-project-name"
498
+ ```
499
+
500
+ #### Step 4: Import to PostgreSQL
501
+
502
+ ```bash
503
+ npx sqlew db:import migration-backup.json
504
+ ```
505
+
506
+ ---
507
+
508
+ ### Post-Migration Verification
509
+
510
+ After any migration, verify your data:
511
+
512
+ #### 1. Check Row Counts
513
+
514
+ Use your database client to compare row counts:
515
+
516
+ ```sql
517
+ -- Count decisions
518
+ SELECT COUNT(*) FROM v4_decisions;
519
+
520
+ -- Count tasks
521
+ SELECT COUNT(*) FROM v4_tasks;
522
+
523
+ -- Count file changes
524
+ SELECT COUNT(*) FROM v4_file_changes;
525
+ ```
526
+
527
+ #### 2. Test MCP Server
528
+
529
+ ```bash
530
+ # Start MCP server with new config
531
+ npx sqlew
532
+
533
+ # Or use MCP Inspector for interactive testing
534
+ npx @modelcontextprotocol/inspector npx sqlew
535
+ ```
536
+
537
+ #### 3. Verify in Claude Code
538
+
539
+ Update your `.mcp.json` to use the new database:
540
+
541
+ ```json
542
+ {
543
+ "mcpServers": {
544
+ "sqlew": {
545
+ "command": "npx",
546
+ "args": ["sqlew", "--config-path", "/path/to/.sqlew/config.toml"]
547
+ }
548
+ }
549
+ }
550
+ ```
551
+
552
+ ---
553
+
554
+ ### Troubleshooting
555
+
556
+ #### Connection Refused
557
+
558
+ ```
559
+ Error: connect ECONNREFUSED 127.0.0.1:3306
560
+ ```
561
+
562
+ **Solution**: Ensure the database server is running and accepting connections on the specified port.
563
+
564
+ #### Authentication Failed
296
565
 
297
- # Import to MySQL
298
- node node_modules/sqlew/dist/cli.js db:import --source=data.json --db-path=mysql://localhost/sqlew
299
566
  ```
567
+ Error: Access denied for user 'sqlew_user'@'localhost'
568
+ ```
569
+
570
+ **Solution**: Verify username and password in config.toml. Check that the user has proper privileges.
571
+
572
+ #### Database Does Not Exist
573
+
574
+ ```
575
+ Error: Unknown database 'sqlew_db'
576
+ ```
577
+
578
+ **Solution**: Create the database first (see Step 2 in migration guides above).
579
+
580
+ #### Permission Denied
581
+
582
+ ```
583
+ Error: permission denied for schema public
584
+ ```
585
+
586
+ **Solution**: Grant schema privileges to the user:
587
+ ```sql
588
+ -- PostgreSQL
589
+ GRANT ALL ON SCHEMA public TO sqlew_user;
590
+ ```
591
+
592
+ #### Import Skipped (Project Exists)
593
+
594
+ ```
595
+ Project "my-project" already exists in target database
596
+ ```
597
+
598
+ **Solution**: Use `--project-name` to specify a different name, or manually delete the existing project from the target database.
599
+
600
+ ---
300
601
 
301
602
  ## Error Handling
302
603
 
@@ -328,10 +629,10 @@ Solution: Ensure all referenced entities exist in export
328
629
 
329
630
  ### Dry-Run Validation
330
631
 
331
- Always test imports with `--dry-run` first:
632
+ Always test imports with `dry-run=true` first:
332
633
 
333
634
  ```bash
334
- node node_modules/sqlew/dist/cli.js db:import --source=data.json --dry-run
635
+ npx sqlew db:import data.json dry-run=true
335
636
  ```
336
637
 
337
638
  This validates:
@@ -365,31 +666,30 @@ This validates:
365
666
 
366
667
  ## Comparison with db:dump
367
668
 
368
- | Feature | db:export (JSON) | db:dump (SQL) |
369
- |--------------------|--------------------------|------------------------------------------|
370
- | Format | JSON data only | SQL DDL + data |
371
- | Schema | Not included | Full schema included |
372
- | Use Case | Project migration | **Backup/restore, database replication** |
373
- | Cross-DB | ✅ Yes | ❌ No (dialect-specific) |
374
- | Size | Smaller (~40% reduction) | Larger (includes schema) |
375
- | Import Speed | Slower (ID remapping) | Faster (direct SQL execution) |
376
- | Conflict Handling | Smart deduplication | Overwrite or fail |
377
- | Restore Capability | ❌ Skips if exists | ✅ Full restore |
378
-
379
- **When to use db:export (JSON)**:
380
-
381
- - Migrating projects between different sqlew databases
382
- - Sharing specific projects with team members
383
- - Merging multiple projects into one database
384
- - Cross-database migration (SQLite MySQL PostgreSQL)
385
-
386
- **When to use db:dump (SQL)** - **RECOMMENDED FOR BACKUP**:
387
-
388
- - **Full database backup with schema**
389
- - **Database restore/recovery**
390
- - Database replication
391
- - Development Production deployment
392
- - Same database type migration
669
+ | Feature | db:export (JSON) | db:dump (SQL) |
670
+ |--------------------|--------------------------------------|---------------------------------------|
671
+ | Format | JSON data only | SQL DDL + data |
672
+ | Schema | Not included | Full schema included |
673
+ | Use Case | **Cross-DB migration**, sharing | **Same-DB backup/restore** |
674
+ | Cross-DB | ✅ **Yes (ONLY option for cross-DB)** | ❌ No (v4.0.2+ same-DB only) |
675
+ | Size | Smaller (~40% reduction) | Larger (includes schema) |
676
+ | Import Speed | Slower (ID remapping) | Faster (direct SQL execution) |
677
+ | Conflict Handling | Smart deduplication | Overwrite or fail |
678
+ | Restore Capability | ❌ Skips if exists | ✅ Full restore |
679
+
680
+ **When to use db:export (JSON)** - **REQUIRED FOR CROSS-DATABASE**:
681
+
682
+ - **Cross-database migration** (SQLite MySQL → PostgreSQL) - **ONLY option**
683
+ - Migrating projects between different sqlew databases
684
+ - Sharing specific projects with team members
685
+ - Merging multiple projects into one database
686
+
687
+ **When to use db:dump (SQL)** - **SAME-DATABASE ONLY**:
688
+
689
+ - **Full database backup with schema** (same DB type)
690
+ - **Database restore/recovery** (same DB type)
691
+ - Database replication (same DB type)
692
+ - Cross-database migration (use JSON instead)
393
693
 
394
694
  See [Database Migration Guide](DATABASE_MIGRATION.md) for complete `db:dump` documentation.
395
695