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
@@ -7,55 +7,62 @@
7
7
  sqlew provides CLI commands for advanced database operations that complement the main MCP server functionality. These
8
8
  commands are useful for database administration, backup/restore, and cross-project data migration.
9
9
 
10
+ > **⚠️ Important**: Database CLI commands must be run via `npm run` from the project directory.
11
+ > `npx` is not supported for database operations.
12
+
10
13
  ## What is CLI Mode?
11
14
 
12
15
  While the primary use of sqlew is as an **MCP server** (integrated with Claude Code via `.mcp.json`), it also provides
13
16
  standalone **CLI commands** for:
14
17
 
15
- - **Database Migration** - Generate SQL dumps for SQLite, MySQL, PostgresSQL migration
18
+ - **Database Migration** - Generate SQL dumps for SQLite, MySQL, PostgreSQL migration
16
19
  - **Project Export/Import** - Share project data across databases or team members
17
20
  - **Backup/Restore** - Create SQL backups with schema and data
18
21
 
19
22
  ## MCP Server vs CLI Mode
20
23
 
21
- | Feature | MCP Server (`npx sqlew`) | CLI Mode |
24
+ | Feature | MCP Server (via `.mcp.json`) | CLI Mode |
22
25
  |-----------------|----------------------------------------|----------------------------------------------|
23
26
  | **Primary Use** | AI agent context management | Database administration |
24
27
  | **Setup** | `.mcp.json` configuration | Per-project npm install |
25
28
  | **Commands** | MCP tools (decision, task, file, etc.) | CLI commands (db:dump, db:export, db:import) |
26
29
  | **When to Use** | Daily AI development workflow | Database migration, backup, data sharing |
27
30
 
28
- ## Installation
31
+ ## Usage
32
+
33
+ ### Within mcp-sqlew Project (Development)
29
34
 
30
- ### Install sqlew in Your Project
35
+ Use npm scripts with `--` to pass arguments:
31
36
 
32
37
  ```bash
33
- cd /path/to/your/project
34
- npm install sqlew
38
+ # Generate MySQL dump
39
+ npm run db:dump -- mysql backup.sql
40
+
41
+ # Export project to JSON
42
+ npm run db:export -- data.json project=myproject
43
+
44
+ # Import from JSON
45
+ npm run db:import -- data.json
35
46
  ```
36
47
 
37
- ### Add npm Script Shortcut (Recommended)
48
+ ### In Projects with sqlew as Dependency
38
49
 
39
50
  Add to your `package.json`:
40
51
 
41
52
  ```json
42
53
  {
43
54
  "scripts": {
44
- "sqlew": "node node_modules/sqlew/dist/cli.js"
55
+ "db:dump": "node node_modules/sqlew/dist/cli.js db:dump",
56
+ "db:export": "node node_modules/sqlew/dist/cli.js db:export",
57
+ "db:import": "node node_modules/sqlew/dist/cli.js db:import"
45
58
  }
46
59
  }
47
60
  ```
48
61
 
49
- Then you can use shorter commands:
50
-
51
- ```bash
52
- npm run sqlew db:dump --format=mysql --output=backup.sql
53
- ```
54
-
55
- ### Direct Command (Without Shortcut)
62
+ Then use:
56
63
 
57
64
  ```bash
58
- node node_modules/sqlew/dist/cli.js db:dump --format=mysql --output=backup.sql
65
+ npm run db:dump -- mysql backup.sql
59
66
  ```
60
67
 
61
68
  ## Available Commands
@@ -67,17 +74,20 @@ Generate complete SQL dumps (schema + data) for database migration or backup.
67
74
  **Use Cases**:
68
75
 
69
76
  - Full database backup with schema
70
- - Cross-database migration (SQLite → MySQL/PostgresSQL)
77
+ - Cross-database migration (SQLite → MySQL/PostgreSQL)
71
78
  - Development → Production deployment
72
79
 
73
80
  **Quick Example**:
74
81
 
75
82
  ```bash
76
- # Backup SQLite to MySQL dump
77
- node node_modules/sqlew/dist/cli.js db:dump --format=mysql --output=backup.sql
83
+ # Generate MySQL dump (positional format argument)
84
+ npm run db:dump -- mysql backup.sql
85
+
86
+ # Generate PostgreSQL dump
87
+ npm run db:dump -- postgresql backup.sql
78
88
 
79
- # Backup to PostgresSQL dump
80
- node node_modules/sqlew/dist/cli.js db:dump --format=postgresql --output=backup.sql
89
+ # MySQL from PostgreSQL source
90
+ npm run db:dump -- mysql backup.sql from=postgresql
81
91
  ```
82
92
 
83
93
  **📖 Full Documentation**: [DATABASE_MIGRATION.md](DATABASE_MIGRATION.md)
@@ -98,10 +108,10 @@ Export project data to JSON format for sharing or multi-project consolidation.
98
108
 
99
109
  ```bash
100
110
  # Export specific project
101
- node node_modules/sqlew/dist/cli.js db:export --project=my-project --output=project.json
111
+ npm run db:export -- project.json project=my-project
102
112
 
103
113
  # Export all projects
104
- node node_modules/sqlew/dist/cli.js db:export --output=all-projects.json
114
+ npm run db:export -- all-projects.json
105
115
  ```
106
116
 
107
117
  **📖 Full Documentation**: [DATA_EXPORT_IMPORT.md](DATA_EXPORT_IMPORT.md#export-command)
@@ -122,28 +132,69 @@ Import project data from JSON export files.
122
132
 
123
133
  ```bash
124
134
  # Import from JSON export
125
- node node_modules/sqlew/dist/cli.js db:import --source=project.json
135
+ npm run db:import -- project.json
126
136
 
127
137
  # Import with custom name
128
- node node_modules/sqlew/dist/cli.js db:import --source=project.json --project-name=new-name
138
+ npm run db:import -- project.json project-name=new-name
129
139
 
130
140
  # Dry-run validation
131
- node node_modules/sqlew/dist/cli.js db:import --source=project.json --dry-run
141
+ npm run db:import -- project.json dry-run=true
132
142
  ```
133
143
 
134
144
  **📖 Full Documentation**: [DATA_EXPORT_IMPORT.md](DATA_EXPORT_IMPORT.md#import-command)
135
145
 
136
146
  ---
137
147
 
148
+ ## Recommended Data Migration Workflow
149
+
150
+ ### Cross-Database Migration (Recommended: JSON)
151
+
152
+ For migrations between different database systems (e.g., SQLite to MySQL, PostgreSQL to MySQL), **use JSON format**:
153
+
154
+ ```bash
155
+ # Step 1: Export from source database
156
+ npm run db:export -- backup.json
157
+
158
+ # Step 2: Configure target database connection
159
+ # (Update your .sqlew/config.toml or environment variables)
160
+
161
+ # Step 3: Import to target database
162
+ npm run db:import -- backup.json
163
+ ```
164
+
165
+ **Why JSON for cross-database migration?**
166
+ - Database-agnostic format - no SQL syntax differences
167
+ - Automatic ID remapping handles foreign key relationships
168
+ - Preserves all data integrity across different RDBMS
169
+
170
+ ### SQL Dump (Same-RDBMS Only)
171
+
172
+ SQL dump (`db:dump`) is designed for **same-database-type operations only**:
173
+
174
+ ```bash
175
+ # SQLite backup (restore to SQLite)
176
+ npm run db:dump -- sqlite backup.sql
177
+
178
+ # MySQL backup (restore to MySQL)
179
+ npm run db:dump -- mysql backup.sql
180
+
181
+ # PostgreSQL backup (restore to PostgreSQL)
182
+ npm run db:dump -- postgresql backup.sql
183
+ ```
184
+
185
+ **Note**: SQL dump does NOT support cross-database migrations (e.g., SQLite to MySQL). The generated SQL contains database-specific syntax that may not be compatible with other RDBMS.
186
+
187
+ ---
188
+
138
189
  ## Quick Comparison: When to Use Which Command
139
190
 
140
191
  | Scenario | Use Command | Restore Capability |
141
192
  |-----------------------------------------------|---------------------------|----------------------------|
142
- | **Full database backup** | `db:dump` | Full restore |
143
- | **Cross-database migration** (SQLite MySQL) | `db:dump` | Full restore |
144
- | **Share project with team** | `db:export` / `db:import` | ⚠️ Skips if project exists |
145
- | **Consolidate multiple projects** | `db:export` / `db:import` | ⚠️ Skips if project exists |
146
- | **Backup/restore same database** | `db:dump` | Full restore |
193
+ | **Full database backup (same RDBMS)** | `db:dump` | Full restore |
194
+ | **Cross-database migration** (SQLite -> MySQL)| `db:export` / `db:import` | Full restore via JSON |
195
+ | **Share project with team** | `db:export` / `db:import` | Skips if project exists |
196
+ | **Consolidate multiple projects** | `db:export` / `db:import` | Skips if project exists |
197
+ | **Backup/restore same database** | `db:dump` | Full restore |
147
198
 
148
199
  **⚠️ Important**: `db:export`/`db:import` uses `--skip-if-exists=true` by default, so it's NOT suitable for
149
200
  backup/restore to the same database. Use `db:dump` for proper backup/restore.
@@ -154,7 +205,7 @@ backup/restore to the same database. Use `db:dump` for proper backup/restore.
154
205
 
155
206
  ```bash
156
207
  # Create SQL backup with schema + data
157
- node node_modules/sqlew/dist/cli.js db:dump --format=sqlite --output=backup-$(date +%Y%m%d).sql
208
+ npm run db:dump -- sqlite backup-$(date +%Y%m%d).sql
158
209
 
159
210
  # Or simple SQLite file copy
160
211
  cp .sqlew/sqlew.db .sqlew/backup-$(date +%Y%m%d).db
@@ -164,36 +215,35 @@ cp .sqlew/sqlew.db .sqlew/backup-$(date +%Y%m%d).db
164
215
 
165
216
  ```bash
166
217
  # Developer A: Export project
167
- node node_modules/sqlew/dist/cli.js db:export --project=feature-x --output=feature-x.json
218
+ npm run db:export -- feature-x.json project=feature-x
168
219
 
169
220
  # Developer B: Import project (in their own database)
170
- node node_modules/sqlew/dist/cli.js db:import --source=feature-x.json
221
+ npm run db:import -- feature-x.json
171
222
  ```
172
223
 
173
224
  ### Workflow 3: Migrate to MySQL from SQLite
174
225
 
175
226
  ```bash
176
227
  # Step 1: Generate MySQL dump
177
- node node_modules/sqlew/dist/cli.js db:dump --format=mysql --output=migrate-to-mysql.sql
228
+ npm run db:dump -- mysql migrate-to-mysql.sql
178
229
 
179
230
  # Step 2: Create MySQL database
180
231
  mysql -e "CREATE DATABASE sqlew_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
181
232
 
182
233
  # Step 3: Import dump
183
- mysql sqlew_db < migrate-to-mysql.sql
234
+ mysql -u user -p sqlew_db < migrate-to-mysql.sql
184
235
  ```
185
236
 
186
- ### Workflow 4: Consolidate Multiple Projects (Permission-Constrained)
237
+ ### Workflow 4: Consolidate Multiple Projects
187
238
 
188
239
  ```bash
189
240
  # Export from each project
190
- cd ~/project-a && node node_modules/sqlew/dist/cli.js db:export --project=project-a --output=/tmp/a.json
191
- cd ~/project-b && node node_modules/sqlew/dist/cli.js db:export --project=project-b --output=/tmp/b.json
241
+ npm run db:export -- /tmp/a.json project=project-a
242
+ npm run db:export -- /tmp/b.json project=project-b
192
243
 
193
244
  # Import all to shared database
194
- cd ~/shared-db
195
- node node_modules/sqlew/dist/cli.js db:import --source=/tmp/a.json
196
- node node_modules/sqlew/dist/cli.js db:import --source=/tmp/b.json
245
+ npm run db:import -- /tmp/a.json
246
+ npm run db:import -- /tmp/b.json
197
247
  ```
198
248
 
199
249
  ## Getting Help
@@ -201,9 +251,9 @@ node node_modules/sqlew/dist/cli.js db:import --source=/tmp/b.json
201
251
  Show command-specific help:
202
252
 
203
253
  ```bash
204
- node node_modules/sqlew/dist/cli.js db:dump --help
205
- node node_modules/sqlew/dist/cli.js db:export --help
206
- node node_modules/sqlew/dist/cli.js db:import --help
254
+ npm run db:dump -- --help
255
+ npm run db:export -- --help
256
+ npm run db:import -- --help
207
257
  ```
208
258
 
209
259
  ## Detailed Documentation
package/package.json CHANGED
@@ -1,13 +1,11 @@
1
1
  {
2
2
  "name": "sqlew",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
4
4
  "description": "MCP server that gives AI agents a shared SQL-backed context repository for decisions, constraints, and tasks",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
7
7
  "bin": {
8
8
  "sqlew": "dist/index.js",
9
- "sqlew-cli": "dist/cli.js",
10
- "sqlew-init-agents": "dist/init-agents.js",
11
9
  "sqlew-init-commands": "dist/init-commands.js"
12
10
  },
13
11
  "files": [
@@ -54,7 +52,6 @@
54
52
  "test:sql-dump:verbose": "node --test --test-force-exit --import tsx \"src/tests/database/sql-dump/**/*.test.ts\"",
55
53
  "test:all-features": "npm run build && node dist/tests/integration/all-features.standalone.js",
56
54
  "test:docker": "npm run build && node --test --test-force-exit dist/tests/docker/**/*.test.js",
57
- "test:cross-db": "npm run build && node --test dist/tests/docker/cross-database.test.js",
58
55
  "test:native": "npm run build && node --test --test-concurrency=1 --test-force-exit dist/tests/docker/native/**/*.test.js | node scripts/filter-test-output.js",
59
56
  "test:native:verbose": "npm run build && node --test --test-concurrency=1 --test-force-exit dist/tests/docker/native/**/*.test.js",
60
57
  "test:migration-upgrade-paths": "echo 'v3 migration tests moved to v3 subdirectory - use test:native for v4 RDBMS tests'",
@@ -72,10 +69,11 @@
72
69
  "seed:make": "npm run knex seed:make",
73
70
  "seed:run": "npm run knex seed:run",
74
71
  "db:dump": "node dist/cli.js db:dump",
75
- "db:export": "node dist/cli.js db:export"
72
+ "db:export": "node dist/cli.js db:export",
73
+ "db:import": "node dist/cli.js db:import"
76
74
  },
77
75
  "engines": {
78
- "node": ">=18.0.0"
76
+ "node": ">=20.0.0"
79
77
  },
80
78
  "repository": {
81
79
  "type": "git",