sqlew 5.1.0 → 5.2.1

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 (83) hide show
  1. package/CHANGELOG.md +2140 -2081
  2. package/LICENSE +190 -190
  3. package/NOTICE +24 -24
  4. package/README.md +204 -190
  5. package/dist/adapters/mysql-adapter.js +3 -3
  6. package/dist/adapters/postgresql-adapter.js +3 -3
  7. package/dist/cli/db-export.js +32 -32
  8. package/dist/cli/db-import.js +30 -30
  9. package/dist/cli/hooks/codex-transcript.d.ts +23 -0
  10. package/dist/cli/hooks/codex-transcript.d.ts.map +1 -0
  11. package/dist/cli/hooks/codex-transcript.js +134 -0
  12. package/dist/cli/hooks/codex-transcript.js.map +1 -0
  13. package/dist/cli/hooks/on-exit-plan.d.ts.map +1 -1
  14. package/dist/cli/hooks/on-exit-plan.js +72 -4
  15. package/dist/cli/hooks/on-exit-plan.js.map +1 -1
  16. package/dist/cli/hooks/on-prompt.d.ts.map +1 -1
  17. package/dist/cli/hooks/on-prompt.js +38 -16
  18. package/dist/cli/hooks/on-prompt.js.map +1 -1
  19. package/dist/cli/hooks/plan-processor.d.ts.map +1 -1
  20. package/dist/cli/hooks/plan-processor.js +16 -2
  21. package/dist/cli/hooks/plan-processor.js.map +1 -1
  22. package/dist/cli/hooks/pr-adr.js +5 -5
  23. package/dist/cli/hooks/stdin-parser.d.ts +43 -0
  24. package/dist/cli/hooks/stdin-parser.d.ts.map +1 -1
  25. package/dist/cli/hooks/stdin-parser.js +212 -6
  26. package/dist/cli/hooks/stdin-parser.js.map +1 -1
  27. package/dist/cli/hooks/track-plan.d.ts +13 -0
  28. package/dist/cli/hooks/track-plan.d.ts.map +1 -1
  29. package/dist/cli/hooks/track-plan.js +73 -18
  30. package/dist/cli/hooks/track-plan.js.map +1 -1
  31. package/dist/cli.js +48 -48
  32. package/dist/config/global-config.d.ts +7 -1
  33. package/dist/config/global-config.d.ts.map +1 -1
  34. package/dist/config/global-config.js +5 -26
  35. package/dist/config/global-config.js.map +1 -1
  36. package/dist/database/migrations/v4/20251126000000_v4_bootstrap.js +32 -32
  37. package/dist/database/migrations/v4/20251126000001_v4_migrate_data.d.ts.map +1 -1
  38. package/dist/database/migrations/v4/20251126000001_v4_migrate_data.js +2 -1
  39. package/dist/database/migrations/v4/20251126000001_v4_migrate_data.js.map +1 -1
  40. package/dist/database/migrations/v4/20260102204000_v4_fix_decision_set_example.js +3 -3
  41. package/dist/help-data/constraint.toml +259 -259
  42. package/dist/help-data/decision.toml +845 -845
  43. package/dist/help-data/queue.toml +134 -134
  44. package/dist/server/tool-schemas.js +30 -30
  45. package/dist/tests/docker/native/db-init.js +9 -9
  46. package/dist/tests/unit/hooks/codex-hook-normalization.test.d.ts +7 -0
  47. package/dist/tests/unit/hooks/codex-hook-normalization.test.d.ts.map +1 -0
  48. package/dist/tests/unit/hooks/codex-hook-normalization.test.js +112 -0
  49. package/dist/tests/unit/hooks/codex-hook-normalization.test.js.map +1 -0
  50. package/dist/tests/unit/hooks/grok-hook-normalization.test.d.ts +9 -0
  51. package/dist/tests/unit/hooks/grok-hook-normalization.test.d.ts.map +1 -0
  52. package/dist/tests/unit/hooks/grok-hook-normalization.test.js +136 -0
  53. package/dist/tests/unit/hooks/grok-hook-normalization.test.js.map +1 -0
  54. package/dist/tests/unit/hooks/grok-plan-template-injection.test.d.ts +7 -0
  55. package/dist/tests/unit/hooks/grok-plan-template-injection.test.d.ts.map +1 -0
  56. package/dist/tests/unit/hooks/grok-plan-template-injection.test.js +55 -0
  57. package/dist/tests/unit/hooks/grok-plan-template-injection.test.js.map +1 -0
  58. package/dist/tests/utils/db-schema.js +48 -48
  59. package/dist/tests/utils/test-helpers.js +48 -48
  60. package/dist/tools/constraints/actions/get.js +5 -5
  61. package/dist/utils/path-normalize.d.ts +23 -0
  62. package/dist/utils/path-normalize.d.ts.map +1 -0
  63. package/dist/utils/path-normalize.js +38 -0
  64. package/dist/utils/path-normalize.js.map +1 -0
  65. package/dist/utils/project-root.d.ts +7 -3
  66. package/dist/utils/project-root.d.ts.map +1 -1
  67. package/dist/utils/project-root.js +17 -3
  68. package/dist/utils/project-root.js.map +1 -1
  69. package/dist/watcher/base-watcher.d.ts +0 -4
  70. package/dist/watcher/base-watcher.d.ts.map +1 -1
  71. package/dist/watcher/base-watcher.js +11 -22
  72. package/dist/watcher/base-watcher.js.map +1 -1
  73. package/docs/ADR_CONCEPTS.md +152 -152
  74. package/docs/CLI_USAGE.md +392 -392
  75. package/docs/CONFIGURATION.md +157 -157
  76. package/docs/CROSS_DATABASE.md +66 -66
  77. package/docs/DATABASE_AUTH.md +135 -135
  78. package/docs/HOOKS_GUIDE.md +116 -67
  79. package/docs/MIGRATION_TO_SAAS.md +176 -176
  80. package/docs/SHARED_DATABASE.md +108 -108
  81. package/package.json +88 -88
  82. package/scripts/copy-help-data.js +19 -19
  83. package/scripts/filter-test-output.js +78 -78
package/docs/CLI_USAGE.md CHANGED
@@ -1,392 +1,392 @@
1
- # CLI Usage Guide
2
-
3
- > Command-line tools for database backup, export/import, and cross-database migration
4
-
5
- ## Overview
6
-
7
- sqlew provides CLI commands for database operations that complement the main MCP server. The primary use of sqlew is as an **MCP server** (integrated via `.mcp.json`), but these CLI commands handle:
8
-
9
- - **Data Export/Import** — JSON-based project data migration (cross-database supported)
10
-
11
- ## Commands
12
-
13
- | Command | Purpose | Cross-DB |
14
- |---------|---------|----------|
15
- | `db:export` | JSON export (recommended for migration) | ✅ |
16
- | `db:import` | JSON import (recommended for migration) | ✅ |
17
-
18
- ### Running CLI Commands
19
-
20
- ```bash
21
- # Direct use (global install or npx)
22
- sqlew db:export backup.json
23
- sqlew db:import backup.json
24
- ```
25
-
26
- **Note**: The first argument determines the mode — `db:export`, `db:import` enter CLI mode; no argument starts the MCP server.
27
-
28
- ---
29
-
30
- ## JSON Export (`db:export`)
31
-
32
- ### Syntax
33
-
34
- ```bash
35
- sqlew db:export [output-file] [key=value ...]
36
- ```
37
-
38
- ### Options
39
-
40
- | Option | Description | Default |
41
- |--------|-------------|---------|
42
- | `project=<name>` | Export specific project by name | Auto-detect from `config.toml` |
43
- | `project=all` | Export all projects (explicit opt-in) | — |
44
- | `db-path=<path>` | Database file path | `~/.config/sqlew/sqlew-shared.db` |
45
- | `config=<path>` | Config file path | Auto-detect |
46
-
47
- > **Security (v5.1.0+)**: With the global shared database, `db:export` no longer exports all projects by default. It auto-detects the project name from `.sqlew/config.toml` `[project].name`. To export all projects, you must explicitly specify `project=all`.
48
-
49
- ### What Gets Exported
50
-
51
- - **Master Tables** (filtered to used entries): m_context_keys, m_tags, m_scopes, m_layers, m_projects
52
- - **Transaction Tables** (all data for selected project): t_decisions, t_decision_context, t_constraints
53
- - **Junction Tables** (relationships): t_decision_tags, t_decision_scopes, t_constraint_tags
54
-
55
- ### Examples
56
-
57
- ```bash
58
- # Export current project (auto-detect from .sqlew/config.toml)
59
- sqlew db:export backup.json
60
-
61
- # Export specific project
62
- sqlew db:export backup.json project=my-project
63
-
64
- # Export all projects (explicit)
65
- sqlew db:export backup.json project=all
66
-
67
- # Export to stdout
68
- sqlew db:export project=my-project
69
- ```
70
-
71
- ---
72
-
73
- ## JSON Import (`db:import`)
74
-
75
- ### Syntax
76
-
77
- ```bash
78
- sqlew db:import <source-file> [key=value ...]
79
- ```
80
-
81
- ### Options
82
-
83
- | Option | Description | Default |
84
- |--------|-------------|---------|
85
- | `<source-file>` | JSON export file path | **Required** |
86
- | `project-name=<name>` | Target project name | Use name from JSON |
87
- | `skip-if-exists=true` | Skip import if project exists | `true` |
88
- | `dry-run=true` | Validate only, don't import | `false` |
89
- | `db-path=<path>` | Database file path | `.sqlew/sqlew.db` |
90
- | `config=<path>` | Config file path | Auto-detect |
91
-
92
- ### Import Process
93
-
94
- 1. **Validation** — Checks JSON format, required fields, data types
95
- 2. **Conflict Detection** — Checks if project name already exists
96
- 3. **ID Remapping** — Creates new IDs for all imported data
97
- 4. **Master Table Merge** — Reuses existing tags/scopes by name
98
- 5. **Transaction Import** — Imports with fresh IDs and translated foreign keys
99
- 6. **Junction Table Import** — Restores all relationships
100
-
101
- ### Smart Features
102
-
103
- - **ID Remapping**: All imported data gets fresh auto-incremented IDs with automatic foreign key updates
104
- - **Master Table Deduplication**: Tags, scopes reused if they already exist (by name)
105
- - **Transaction Safety**: All-or-nothing semantics (full rollback on any error)
106
-
107
- ### Examples
108
-
109
- ```bash
110
- # Import from JSON
111
- sqlew db:import backup.json
112
-
113
- # Import with custom project name
114
- sqlew db:import backup.json project-name=new-name
115
-
116
- # Dry-run validation (no actual import)
117
- sqlew db:import backup.json dry-run=true
118
- ```
119
-
120
- **⚠️ Important**: Import uses `skip-if-exists=true` by default — it skips if the project name already exists. For full backup/restore, use a file copy of the SQLite database.
121
-
122
- ---
123
-
124
- ## Cross-Database Migration
125
-
126
- > **v4.0.2+**: JSON export/import is the **ONLY** supported method for cross-database migrations.
127
-
128
- ### Pre-Migration Checklist
129
-
130
- - [ ] Backup your current database
131
- - [ ] Target database is created and accessible
132
- - [ ] Database credentials are available
133
- - [ ] Required privileges: SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, INDEX, DROP, REFERENCES
134
-
135
- ### SQLite → MySQL
136
-
137
- **Step 1: Export from SQLite**
138
-
139
- ```bash
140
- # Exports current project (from .sqlew/config.toml [project].name)
141
- sqlew db:export migration-backup.json
142
-
143
- # Or export all projects for full migration
144
- sqlew db:export migration-backup.json project=all
145
- ```
146
-
147
- **Step 2: Prepare MySQL**
148
-
149
- ```sql
150
- CREATE DATABASE sqlew_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
151
- CREATE USER 'sqlew_user'@'localhost' IDENTIFIED BY 'your-secure-password';
152
- GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, INDEX, DROP, REFERENCES
153
- ON sqlew_db.* TO 'sqlew_user'@'localhost';
154
- FLUSH PRIVILEGES;
155
- ```
156
-
157
- **Step 3: Configure `.sqlew/config.toml`**
158
-
159
- ```toml
160
- [database]
161
- type = "mysql"
162
-
163
- [database.connection]
164
- host = "localhost"
165
- port = 3306
166
- database = "sqlew_db"
167
-
168
- [database.auth]
169
- type = "direct"
170
- user = "sqlew_user"
171
- password = "your-secure-password"
172
-
173
- [project]
174
- name = "your-project-name"
175
- ```
176
-
177
- **Step 4: Import**
178
-
179
- ```bash
180
- sqlew db:import migration-backup.json
181
- ```
182
-
183
- ### SQLite → PostgreSQL
184
-
185
- **Step 1: Export from SQLite**
186
-
187
- ```bash
188
- # Exports current project (from .sqlew/config.toml [project].name)
189
- sqlew db:export migration-backup.json
190
-
191
- # Or export all projects for full migration
192
- sqlew db:export migration-backup.json project=all
193
- ```
194
-
195
- **Step 2: Prepare PostgreSQL**
196
-
197
- ```sql
198
- CREATE DATABASE sqlew_db WITH ENCODING 'UTF8';
199
- CREATE USER sqlew_user WITH PASSWORD 'your-secure-password';
200
- GRANT ALL PRIVILEGES ON DATABASE sqlew_db TO sqlew_user;
201
- \c sqlew_db
202
- GRANT ALL ON SCHEMA public TO sqlew_user;
203
- ```
204
-
205
- **Step 3: Configure `.sqlew/config.toml`**
206
-
207
- ```toml
208
- [database]
209
- type = "postgres"
210
-
211
- [database.connection]
212
- host = "localhost"
213
- port = 5432
214
- database = "sqlew_db"
215
-
216
- [database.auth]
217
- type = "direct"
218
- user = "sqlew_user"
219
- password = "your-secure-password"
220
-
221
- [project]
222
- name = "your-project-name"
223
- ```
224
-
225
- **Step 4: Import**
226
-
227
- ```bash
228
- sqlew db:import migration-backup.json
229
- ```
230
-
231
- ### MySQL → PostgreSQL
232
-
233
- **Step 1: Export from MySQL**
234
-
235
- Configure `.sqlew/config.toml` for MySQL, then:
236
-
237
- ```bash
238
- # Exports current project (from .sqlew/config.toml [project].name)
239
- sqlew db:export migration-backup.json
240
-
241
- # Or export all projects for full migration
242
- sqlew db:export migration-backup.json project=all
243
- ```
244
-
245
- **Step 2: Prepare PostgreSQL**
246
-
247
- ```sql
248
- CREATE DATABASE sqlew_db WITH ENCODING 'UTF8';
249
- CREATE USER sqlew_user WITH PASSWORD 'postgres-password';
250
- GRANT ALL PRIVILEGES ON DATABASE sqlew_db TO sqlew_user;
251
- \c sqlew_db
252
- GRANT ALL ON SCHEMA public TO sqlew_user;
253
- ```
254
-
255
- **Step 3: Update `.sqlew/config.toml` for PostgreSQL**
256
-
257
- ```toml
258
- [database]
259
- type = "postgres"
260
-
261
- [database.connection]
262
- host = "localhost"
263
- port = 5432
264
- database = "sqlew_db"
265
-
266
- [database.auth]
267
- type = "direct"
268
- user = "sqlew_user"
269
- password = "postgres-password"
270
-
271
- [project]
272
- name = "your-project-name"
273
- ```
274
-
275
- **Step 4: Import**
276
-
277
- ```bash
278
- sqlew db:import migration-backup.json
279
- ```
280
-
281
- ### Post-Migration Verification
282
-
283
- ```bash
284
- # Test MCP server connection
285
- sqlew --config-path=.sqlew/config.toml
286
-
287
- # Or use MCP Inspector
288
- npx @modelcontextprotocol/inspector sqlew
289
- ```
290
-
291
- Update `.mcp.json` to use the new database:
292
-
293
- ```json
294
- {
295
- "mcpServers": {
296
- "sqlew": {
297
- "command": "npx",
298
- "args": ["sqlew", "--config-path", "/path/to/.sqlew/config.toml"]
299
- }
300
- }
301
- }
302
- ```
303
-
304
- ---
305
-
306
- ## Use Cases
307
-
308
- ### Project Sharing
309
-
310
- ```bash
311
- # Developer A: Export
312
- sqlew db:export feature-x.json project=feature-x
313
-
314
- # Developer B: Import
315
- sqlew db:import feature-x.json
316
- ```
317
-
318
- ### Multi-Project Consolidation
319
-
320
- ```bash
321
- # Export from each project
322
- sqlew db:export /tmp/a.json project=project-a
323
- sqlew db:export /tmp/b.json project=project-b
324
-
325
- # Import all to shared database
326
- sqlew db:import /tmp/a.json
327
- sqlew db:import /tmp/b.json
328
- ```
329
-
330
- ### Full Database Backup
331
-
332
- ```bash
333
- # Simple file copy (SQLite global DB)
334
- cp ~/.config/sqlew/sqlew-shared.db ~/backup-$(date +%Y%m%d).db
335
-
336
- # Or JSON export (cross-database compatible, all projects)
337
- sqlew db:export backup-$(date +%Y%m%d).json project=all
338
- ```
339
-
340
- ---
341
-
342
- ## Troubleshooting
343
-
344
- ### Connection Refused
345
-
346
- ```
347
- Error: connect ECONNREFUSED 127.0.0.1:3306
348
- ```
349
-
350
- Ensure the database server is running and accepting connections on the specified port.
351
-
352
- ### Authentication Failed
353
-
354
- ```
355
- Error: Access denied for user 'sqlew_user'@'localhost'
356
- ```
357
-
358
- Verify username and password in config.toml. Check that the user has proper privileges.
359
-
360
- ### Database Does Not Exist
361
-
362
- ```
363
- Error: Unknown database 'sqlew_db'
364
- ```
365
-
366
- Create the database first (see migration steps above).
367
-
368
- ### Permission Denied (PostgreSQL)
369
-
370
- ```
371
- Error: permission denied for schema public
372
- ```
373
-
374
- Grant schema privileges: `GRANT ALL ON SCHEMA public TO sqlew_user;`
375
-
376
- ### Import Skipped (Project Exists)
377
-
378
- ```
379
- Project "my-project" already exists in target database
380
- ```
381
-
382
- Use `project-name=<new-name>` to specify a different name, or remove the existing project from the target database.
383
-
384
- ### Dry-Run Validation
385
-
386
- Always test imports with dry-run first:
387
-
388
- ```bash
389
- sqlew db:import data.json dry-run=true
390
- ```
391
-
392
- Validates JSON format, project name conflicts, foreign key references, and data type correctness.
1
+ # CLI Usage Guide
2
+
3
+ > Command-line tools for database backup, export/import, and cross-database migration
4
+
5
+ ## Overview
6
+
7
+ sqlew provides CLI commands for database operations that complement the main MCP server. The primary use of sqlew is as an **MCP server** (integrated via `.mcp.json`), but these CLI commands handle:
8
+
9
+ - **Data Export/Import** — JSON-based project data migration (cross-database supported)
10
+
11
+ ## Commands
12
+
13
+ | Command | Purpose | Cross-DB |
14
+ |---------|---------|----------|
15
+ | `db:export` | JSON export (recommended for migration) | ✅ |
16
+ | `db:import` | JSON import (recommended for migration) | ✅ |
17
+
18
+ ### Running CLI Commands
19
+
20
+ ```bash
21
+ # Direct use (global install or npx)
22
+ sqlew db:export backup.json
23
+ sqlew db:import backup.json
24
+ ```
25
+
26
+ **Note**: The first argument determines the mode — `db:export`, `db:import` enter CLI mode; no argument starts the MCP server.
27
+
28
+ ---
29
+
30
+ ## JSON Export (`db:export`)
31
+
32
+ ### Syntax
33
+
34
+ ```bash
35
+ sqlew db:export [output-file] [key=value ...]
36
+ ```
37
+
38
+ ### Options
39
+
40
+ | Option | Description | Default |
41
+ |--------|-------------|---------|
42
+ | `project=<name>` | Export specific project by name | Auto-detect from `config.toml` |
43
+ | `project=all` | Export all projects (explicit opt-in) | — |
44
+ | `db-path=<path>` | Database file path | `~/.config/sqlew/sqlew-shared.db` |
45
+ | `config=<path>` | Config file path | Auto-detect |
46
+
47
+ > **Security (v5.1.0+)**: With the global shared database, `db:export` no longer exports all projects by default. It auto-detects the project name from `.sqlew/config.toml` `[project].name`. To export all projects, you must explicitly specify `project=all`.
48
+
49
+ ### What Gets Exported
50
+
51
+ - **Master Tables** (filtered to used entries): m_context_keys, m_tags, m_scopes, m_layers, m_projects
52
+ - **Transaction Tables** (all data for selected project): t_decisions, t_decision_context, t_constraints
53
+ - **Junction Tables** (relationships): t_decision_tags, t_decision_scopes, t_constraint_tags
54
+
55
+ ### Examples
56
+
57
+ ```bash
58
+ # Export current project (auto-detect from .sqlew/config.toml)
59
+ sqlew db:export backup.json
60
+
61
+ # Export specific project
62
+ sqlew db:export backup.json project=my-project
63
+
64
+ # Export all projects (explicit)
65
+ sqlew db:export backup.json project=all
66
+
67
+ # Export to stdout
68
+ sqlew db:export project=my-project
69
+ ```
70
+
71
+ ---
72
+
73
+ ## JSON Import (`db:import`)
74
+
75
+ ### Syntax
76
+
77
+ ```bash
78
+ sqlew db:import <source-file> [key=value ...]
79
+ ```
80
+
81
+ ### Options
82
+
83
+ | Option | Description | Default |
84
+ |--------|-------------|---------|
85
+ | `<source-file>` | JSON export file path | **Required** |
86
+ | `project-name=<name>` | Target project name | Use name from JSON |
87
+ | `skip-if-exists=true` | Skip import if project exists | `true` |
88
+ | `dry-run=true` | Validate only, don't import | `false` |
89
+ | `db-path=<path>` | Database file path | `.sqlew/sqlew.db` |
90
+ | `config=<path>` | Config file path | Auto-detect |
91
+
92
+ ### Import Process
93
+
94
+ 1. **Validation** — Checks JSON format, required fields, data types
95
+ 2. **Conflict Detection** — Checks if project name already exists
96
+ 3. **ID Remapping** — Creates new IDs for all imported data
97
+ 4. **Master Table Merge** — Reuses existing tags/scopes by name
98
+ 5. **Transaction Import** — Imports with fresh IDs and translated foreign keys
99
+ 6. **Junction Table Import** — Restores all relationships
100
+
101
+ ### Smart Features
102
+
103
+ - **ID Remapping**: All imported data gets fresh auto-incremented IDs with automatic foreign key updates
104
+ - **Master Table Deduplication**: Tags, scopes reused if they already exist (by name)
105
+ - **Transaction Safety**: All-or-nothing semantics (full rollback on any error)
106
+
107
+ ### Examples
108
+
109
+ ```bash
110
+ # Import from JSON
111
+ sqlew db:import backup.json
112
+
113
+ # Import with custom project name
114
+ sqlew db:import backup.json project-name=new-name
115
+
116
+ # Dry-run validation (no actual import)
117
+ sqlew db:import backup.json dry-run=true
118
+ ```
119
+
120
+ **⚠️ Important**: Import uses `skip-if-exists=true` by default — it skips if the project name already exists. For full backup/restore, use a file copy of the SQLite database.
121
+
122
+ ---
123
+
124
+ ## Cross-Database Migration
125
+
126
+ > **v4.0.2+**: JSON export/import is the **ONLY** supported method for cross-database migrations.
127
+
128
+ ### Pre-Migration Checklist
129
+
130
+ - [ ] Backup your current database
131
+ - [ ] Target database is created and accessible
132
+ - [ ] Database credentials are available
133
+ - [ ] Required privileges: SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, INDEX, DROP, REFERENCES
134
+
135
+ ### SQLite → MySQL
136
+
137
+ **Step 1: Export from SQLite**
138
+
139
+ ```bash
140
+ # Exports current project (from .sqlew/config.toml [project].name)
141
+ sqlew db:export migration-backup.json
142
+
143
+ # Or export all projects for full migration
144
+ sqlew db:export migration-backup.json project=all
145
+ ```
146
+
147
+ **Step 2: Prepare MySQL**
148
+
149
+ ```sql
150
+ CREATE DATABASE sqlew_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
151
+ CREATE USER 'sqlew_user'@'localhost' IDENTIFIED BY 'your-secure-password';
152
+ GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, INDEX, DROP, REFERENCES
153
+ ON sqlew_db.* TO 'sqlew_user'@'localhost';
154
+ FLUSH PRIVILEGES;
155
+ ```
156
+
157
+ **Step 3: Configure `.sqlew/config.toml`**
158
+
159
+ ```toml
160
+ [database]
161
+ type = "mysql"
162
+
163
+ [database.connection]
164
+ host = "localhost"
165
+ port = 3306
166
+ database = "sqlew_db"
167
+
168
+ [database.auth]
169
+ type = "direct"
170
+ user = "sqlew_user"
171
+ password = "your-secure-password"
172
+
173
+ [project]
174
+ name = "your-project-name"
175
+ ```
176
+
177
+ **Step 4: Import**
178
+
179
+ ```bash
180
+ sqlew db:import migration-backup.json
181
+ ```
182
+
183
+ ### SQLite → PostgreSQL
184
+
185
+ **Step 1: Export from SQLite**
186
+
187
+ ```bash
188
+ # Exports current project (from .sqlew/config.toml [project].name)
189
+ sqlew db:export migration-backup.json
190
+
191
+ # Or export all projects for full migration
192
+ sqlew db:export migration-backup.json project=all
193
+ ```
194
+
195
+ **Step 2: Prepare PostgreSQL**
196
+
197
+ ```sql
198
+ CREATE DATABASE sqlew_db WITH ENCODING 'UTF8';
199
+ CREATE USER sqlew_user WITH PASSWORD 'your-secure-password';
200
+ GRANT ALL PRIVILEGES ON DATABASE sqlew_db TO sqlew_user;
201
+ \c sqlew_db
202
+ GRANT ALL ON SCHEMA public TO sqlew_user;
203
+ ```
204
+
205
+ **Step 3: Configure `.sqlew/config.toml`**
206
+
207
+ ```toml
208
+ [database]
209
+ type = "postgres"
210
+
211
+ [database.connection]
212
+ host = "localhost"
213
+ port = 5432
214
+ database = "sqlew_db"
215
+
216
+ [database.auth]
217
+ type = "direct"
218
+ user = "sqlew_user"
219
+ password = "your-secure-password"
220
+
221
+ [project]
222
+ name = "your-project-name"
223
+ ```
224
+
225
+ **Step 4: Import**
226
+
227
+ ```bash
228
+ sqlew db:import migration-backup.json
229
+ ```
230
+
231
+ ### MySQL → PostgreSQL
232
+
233
+ **Step 1: Export from MySQL**
234
+
235
+ Configure `.sqlew/config.toml` for MySQL, then:
236
+
237
+ ```bash
238
+ # Exports current project (from .sqlew/config.toml [project].name)
239
+ sqlew db:export migration-backup.json
240
+
241
+ # Or export all projects for full migration
242
+ sqlew db:export migration-backup.json project=all
243
+ ```
244
+
245
+ **Step 2: Prepare PostgreSQL**
246
+
247
+ ```sql
248
+ CREATE DATABASE sqlew_db WITH ENCODING 'UTF8';
249
+ CREATE USER sqlew_user WITH PASSWORD 'postgres-password';
250
+ GRANT ALL PRIVILEGES ON DATABASE sqlew_db TO sqlew_user;
251
+ \c sqlew_db
252
+ GRANT ALL ON SCHEMA public TO sqlew_user;
253
+ ```
254
+
255
+ **Step 3: Update `.sqlew/config.toml` for PostgreSQL**
256
+
257
+ ```toml
258
+ [database]
259
+ type = "postgres"
260
+
261
+ [database.connection]
262
+ host = "localhost"
263
+ port = 5432
264
+ database = "sqlew_db"
265
+
266
+ [database.auth]
267
+ type = "direct"
268
+ user = "sqlew_user"
269
+ password = "postgres-password"
270
+
271
+ [project]
272
+ name = "your-project-name"
273
+ ```
274
+
275
+ **Step 4: Import**
276
+
277
+ ```bash
278
+ sqlew db:import migration-backup.json
279
+ ```
280
+
281
+ ### Post-Migration Verification
282
+
283
+ ```bash
284
+ # Test MCP server connection
285
+ sqlew --config-path=.sqlew/config.toml
286
+
287
+ # Or use MCP Inspector
288
+ npx @modelcontextprotocol/inspector sqlew
289
+ ```
290
+
291
+ Update `.mcp.json` to use the new database:
292
+
293
+ ```json
294
+ {
295
+ "mcpServers": {
296
+ "sqlew": {
297
+ "command": "npx",
298
+ "args": ["sqlew", "--config-path", "/path/to/.sqlew/config.toml"]
299
+ }
300
+ }
301
+ }
302
+ ```
303
+
304
+ ---
305
+
306
+ ## Use Cases
307
+
308
+ ### Project Sharing
309
+
310
+ ```bash
311
+ # Developer A: Export
312
+ sqlew db:export feature-x.json project=feature-x
313
+
314
+ # Developer B: Import
315
+ sqlew db:import feature-x.json
316
+ ```
317
+
318
+ ### Multi-Project Consolidation
319
+
320
+ ```bash
321
+ # Export from each project
322
+ sqlew db:export /tmp/a.json project=project-a
323
+ sqlew db:export /tmp/b.json project=project-b
324
+
325
+ # Import all to shared database
326
+ sqlew db:import /tmp/a.json
327
+ sqlew db:import /tmp/b.json
328
+ ```
329
+
330
+ ### Full Database Backup
331
+
332
+ ```bash
333
+ # Simple file copy (SQLite global DB)
334
+ cp ~/.config/sqlew/sqlew-shared.db ~/backup-$(date +%Y%m%d).db
335
+
336
+ # Or JSON export (cross-database compatible, all projects)
337
+ sqlew db:export backup-$(date +%Y%m%d).json project=all
338
+ ```
339
+
340
+ ---
341
+
342
+ ## Troubleshooting
343
+
344
+ ### Connection Refused
345
+
346
+ ```
347
+ Error: connect ECONNREFUSED 127.0.0.1:3306
348
+ ```
349
+
350
+ Ensure the database server is running and accepting connections on the specified port.
351
+
352
+ ### Authentication Failed
353
+
354
+ ```
355
+ Error: Access denied for user 'sqlew_user'@'localhost'
356
+ ```
357
+
358
+ Verify username and password in config.toml. Check that the user has proper privileges.
359
+
360
+ ### Database Does Not Exist
361
+
362
+ ```
363
+ Error: Unknown database 'sqlew_db'
364
+ ```
365
+
366
+ Create the database first (see migration steps above).
367
+
368
+ ### Permission Denied (PostgreSQL)
369
+
370
+ ```
371
+ Error: permission denied for schema public
372
+ ```
373
+
374
+ Grant schema privileges: `GRANT ALL ON SCHEMA public TO sqlew_user;`
375
+
376
+ ### Import Skipped (Project Exists)
377
+
378
+ ```
379
+ Project "my-project" already exists in target database
380
+ ```
381
+
382
+ Use `project-name=<new-name>` to specify a different name, or remove the existing project from the target database.
383
+
384
+ ### Dry-Run Validation
385
+
386
+ Always test imports with dry-run first:
387
+
388
+ ```bash
389
+ sqlew db:import data.json dry-run=true
390
+ ```
391
+
392
+ Validates JSON format, project name conflicts, foreign key references, and data type correctness.