sqlew 3.7.3 → 3.7.4
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.
- package/CHANGELOG.md +184 -0
- package/LICENSE +0 -0
- package/README.md +2 -2
- package/assets/config.example.toml +0 -0
- package/assets/kanban-style.png +0 -0
- package/assets/sample-agents/README.md +0 -0
- package/assets/sample-agents/sqlew-architect.md +0 -0
- package/assets/sample-agents/sqlew-researcher.md +0 -0
- package/assets/sample-agents/sqlew-scrum-master.md +0 -0
- package/assets/schema.sql +0 -0
- package/assets/sqlew-logo.png +0 -0
- package/dist/cli/db-export.d.ts +29 -0
- package/dist/cli/db-export.d.ts.map +1 -0
- package/dist/cli/db-export.js +251 -0
- package/dist/cli/db-export.js.map +1 -0
- package/dist/cli/db-import.d.ts +31 -0
- package/dist/cli/db-import.d.ts.map +1 -0
- package/dist/cli/db-import.js +258 -0
- package/dist/cli/db-import.js.map +1 -0
- package/dist/cli.js +24 -2
- package/dist/cli.js.map +1 -1
- package/dist/tests/migrations/test-all-versions-real.js +3 -2
- package/dist/tests/migrations/test-all-versions-real.js.map +1 -1
- package/dist/types.d.ts +121 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/exporter/export.d.ts +100 -0
- package/dist/utils/exporter/export.d.ts.map +1 -0
- package/dist/utils/exporter/export.js +363 -0
- package/dist/utils/exporter/export.js.map +1 -0
- package/dist/utils/importer/import.d.ts +29 -0
- package/dist/utils/importer/import.d.ts.map +1 -0
- package/dist/utils/importer/import.js +514 -0
- package/dist/utils/importer/import.js.map +1 -0
- package/dist/utils/importer/master-tables.d.ts +18 -0
- package/dist/utils/importer/master-tables.d.ts.map +1 -0
- package/dist/utils/importer/master-tables.js +255 -0
- package/dist/utils/importer/master-tables.js.map +1 -0
- package/dist/utils/importer/topological-sort.d.ts +61 -0
- package/dist/utils/importer/topological-sort.d.ts.map +1 -0
- package/dist/utils/importer/topological-sort.js +143 -0
- package/dist/utils/importer/topological-sort.js.map +1 -0
- package/docs/ACCEPTANCE_CRITERIA.md +0 -0
- package/docs/AI_AGENT_GUIDE.md +0 -0
- package/docs/ARCHITECTURE.md +0 -0
- package/docs/AUTO_FILE_TRACKING.md +0 -1
- package/docs/BEST_PRACTICES.md +0 -0
- package/docs/CONFIGURATION.md +0 -0
- package/docs/DATABASE_AUTH.md +1 -2
- package/docs/DECISION_CONTEXT.md +0 -0
- package/docs/DECISION_TO_TASK_MIGRATION_GUIDE.md +0 -0
- package/docs/GIT_AWARE_AUTO_COMPLETE.md +0 -0
- package/docs/SHARED_CONCEPTS.md +0 -0
- package/docs/SPECIALIZED_AGENTS.md +0 -0
- package/docs/TASK_ACTIONS.md +0 -0
- package/docs/TASK_DEPENDENCIES.md +0 -0
- package/docs/TASK_LINKING.md +0 -0
- package/docs/TASK_MIGRATION.md +0 -0
- package/docs/TASK_OVERVIEW.md +0 -0
- package/docs/TASK_PRUNING.md +0 -0
- package/docs/TASK_SYSTEM.md +0 -0
- package/docs/TOOL_REFERENCE.md +0 -2
- package/docs/TOOL_SELECTION.md +0 -0
- package/docs/WORKFLOWS.md +0 -0
- package/docs/{DATABASE_MIGRATION.md → cli/DATABASE_MIGRATION.md} +71 -32
- package/docs/cli/DATA_EXPORT_IMPORT.md +400 -0
- package/docs/cli/README.md +227 -0
- package/package.json +3 -2
- package/docs/BASEADAPTER_IMPLEMENTATION.md +0 -399
- package/docs/HELP_PREVIEW_COMPARISON.md +0 -259
- package/docs/MIGRATION_CHAIN.md +0 -293
- package/docs/MIGRATION_v2.md +0 -538
- package/docs/MIGRATION_v3.3.md +0 -602
- package/docs/MIGRATION_v3.6.0.md +0 -170
- package/docs/MULTI_PROJECT_ARCHITECTURE.md +0 -497
|
@@ -1,20 +1,45 @@
|
|
|
1
1
|
# Database Migration Guide
|
|
2
2
|
|
|
3
|
-
This guide explains how to generate complete SQL dumps from your mcp-sqlew database for use with SQLite, MySQL/MariaDB,
|
|
3
|
+
This guide explains how to generate complete SQL dumps from your mcp-sqlew database for use with SQLite, MySQL/MariaDB,
|
|
4
|
+
or PostgreSQL.
|
|
4
5
|
|
|
5
6
|
## Overview
|
|
6
7
|
|
|
7
|
-
The `db:dump` CLI tool generates complete SQL dumps (CREATE TABLE + INSERT statements) compatible with SQLite,
|
|
8
|
+
The `db:dump` CLI tool generates complete SQL dumps (CREATE TABLE + INSERT statements) compatible with SQLite,
|
|
9
|
+
MySQL/MariaDB, and PostgreSQL formats. The generated SQL can be imported directly into an empty database without
|
|
10
|
+
additional setup.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
To use the `db:dump` CLI command, install sqlew in your project:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
cd /path/to/your/project
|
|
18
|
+
npm install sqlew
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Tip**: Add a shortcut to your `package.json` for convenience:
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{
|
|
25
|
+
"scripts": {
|
|
26
|
+
"sqlew": "node node_modules/sqlew/dist/cli.js"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Then you can use: `npm run sqlew db:dump --format=mysql --output=dump.sql`
|
|
8
32
|
|
|
9
33
|
## Usage
|
|
10
34
|
|
|
11
35
|
### Basic Syntax
|
|
12
36
|
|
|
13
37
|
```bash
|
|
14
|
-
|
|
38
|
+
node node_modules/sqlew/dist/cli.js db:dump [--from <source>] --format <target> [options]
|
|
15
39
|
```
|
|
16
40
|
|
|
17
41
|
**Parameters:**
|
|
42
|
+
|
|
18
43
|
- `--from <source>`: Source database (sqlite, mysql, postgresql). Default: sqlite
|
|
19
44
|
- `--format <target>`: Target SQL format (sqlite, mysql, postgresql). **Required**
|
|
20
45
|
- `--output <file>`: Output file path (omit for stdout)
|
|
@@ -29,12 +54,14 @@ npx sqlew db:dump [--from <source>] --format <target> [options]
|
|
|
29
54
|
### Generate SQL Dumps
|
|
30
55
|
|
|
31
56
|
**From SQLite (default):**
|
|
57
|
+
|
|
32
58
|
```bash
|
|
33
|
-
|
|
34
|
-
|
|
59
|
+
node node_modules/sqlew/dist/cli.js db:dump --format mysql --output dump-mysql.sql
|
|
60
|
+
node node_modules/sqlew/dist/cli.js db:dump --format postgresql --output dump-pg.sql
|
|
35
61
|
```
|
|
36
62
|
|
|
37
63
|
**From MySQL:**
|
|
64
|
+
|
|
38
65
|
```bash
|
|
39
66
|
# Configure connection via environment variables
|
|
40
67
|
export MYSQL_HOST=127.0.0.1
|
|
@@ -43,11 +70,12 @@ export MYSQL_USER=youruser
|
|
|
43
70
|
export MYSQL_PASSWORD=yourpass
|
|
44
71
|
export MYSQL_DATABASE=mcp_context
|
|
45
72
|
|
|
46
|
-
|
|
47
|
-
|
|
73
|
+
node node_modules/sqlew/dist/cli.js db:dump --from mysql --format sqlite --output dump-sqlite.sql
|
|
74
|
+
node node_modules/sqlew/dist/cli.js db:dump --from mysql --format postgresql --output dump-pg.sql
|
|
48
75
|
```
|
|
49
76
|
|
|
50
77
|
**From PostgreSQL:**
|
|
78
|
+
|
|
51
79
|
```bash
|
|
52
80
|
# Configure connection via environment variables
|
|
53
81
|
export PG_HOST=localhost
|
|
@@ -56,8 +84,8 @@ export PG_USER=postgres
|
|
|
56
84
|
export PG_PASSWORD=yourpass
|
|
57
85
|
export PG_DATABASE=mcp_context
|
|
58
86
|
|
|
59
|
-
|
|
60
|
-
|
|
87
|
+
node node_modules/sqlew/dist/cli.js db:dump --from postgresql --format sqlite --output dump-sqlite.sql
|
|
88
|
+
node node_modules/sqlew/dist/cli.js db:dump --from postgresql --format mysql --output dump-mysql.sql
|
|
61
89
|
```
|
|
62
90
|
|
|
63
91
|
### Selective Table Export
|
|
@@ -65,7 +93,7 @@ npx sqlew db:dump --from postgresql --format mysql --output dump-mysql.sql
|
|
|
65
93
|
Export only specific tables:
|
|
66
94
|
|
|
67
95
|
```bash
|
|
68
|
-
|
|
96
|
+
node node_modules/sqlew/dist/cli.js db:dump --format mysql --tables t_decisions,t_tasks,m_agents --output partial.sql
|
|
69
97
|
```
|
|
70
98
|
|
|
71
99
|
### Custom Chunk Size
|
|
@@ -73,7 +101,7 @@ npx sqlew db:dump --format mysql --tables t_decisions,t_tasks,m_agents --output
|
|
|
73
101
|
For large tables, adjust INSERT batch size:
|
|
74
102
|
|
|
75
103
|
```bash
|
|
76
|
-
|
|
104
|
+
node node_modules/sqlew/dist/cli.js db:dump --format mysql --chunk-size 500 --output dump.sql
|
|
77
105
|
```
|
|
78
106
|
|
|
79
107
|
### Data-Only Dumps
|
|
@@ -81,10 +109,11 @@ npx sqlew db:dump --format mysql --chunk-size 500 --output dump.sql
|
|
|
81
109
|
For advanced use cases where you manage schema separately:
|
|
82
110
|
|
|
83
111
|
```bash
|
|
84
|
-
|
|
112
|
+
node node_modules/sqlew/dist/cli.js db:dump --format mysql --exclude-schema --output data-only.sql
|
|
85
113
|
```
|
|
86
114
|
|
|
87
115
|
This generates INSERT statements without CREATE TABLE, useful for:
|
|
116
|
+
|
|
88
117
|
- Importing into databases with existing schema
|
|
89
118
|
- Backup/restore of data only
|
|
90
119
|
- Data transfer between identical schemas
|
|
@@ -95,21 +124,23 @@ Handle duplicate keys when importing into existing databases:
|
|
|
95
124
|
|
|
96
125
|
```bash
|
|
97
126
|
# Ignore duplicates (safe for adding new data)
|
|
98
|
-
|
|
127
|
+
node node_modules/sqlew/dist/cli.js db:dump --format mysql --on-conflict ignore --output dump.sql
|
|
99
128
|
|
|
100
129
|
# Update existing rows (sync/overwrite mode)
|
|
101
|
-
|
|
130
|
+
node node_modules/sqlew/dist/cli.js db:dump --format mysql --on-conflict replace --output dump.sql
|
|
102
131
|
|
|
103
132
|
# Fail on duplicates (default, strict mode)
|
|
104
|
-
|
|
133
|
+
node node_modules/sqlew/dist/cli.js db:dump --format mysql --on-conflict error --output dump.sql
|
|
105
134
|
```
|
|
106
135
|
|
|
107
136
|
**Modes:**
|
|
137
|
+
|
|
108
138
|
- `error` (default): Standard INSERT, fails if duplicate keys exist
|
|
109
139
|
- `ignore`: Skip duplicate rows (INSERT IGNORE / ON CONFLICT DO NOTHING)
|
|
110
140
|
- `replace`: Update existing rows with new values (ON DUPLICATE KEY UPDATE / ON CONFLICT DO UPDATE)
|
|
111
141
|
|
|
112
142
|
**Use cases:**
|
|
143
|
+
|
|
113
144
|
- `ignore`: Importing into a database that may already have some data
|
|
114
145
|
- `replace`: Synchronizing data from one database to another
|
|
115
146
|
- `error`: Fresh database migration where duplicates indicate a problem
|
|
@@ -120,14 +151,14 @@ npx sqlew db:dump --format mysql --on-conflict error --output dump.sql
|
|
|
120
151
|
|
|
121
152
|
The `db:dump` tool supports **all 6 migration paths** between SQLite, MySQL/MariaDB, and PostgreSQL:
|
|
122
153
|
|
|
123
|
-
| Source
|
|
124
|
-
|
|
125
|
-
| SQLite
|
|
126
|
-
| SQLite
|
|
127
|
-
| MySQL
|
|
128
|
-
| PostgreSQL | SQLite
|
|
129
|
-
| MySQL
|
|
130
|
-
| PostgreSQL | MySQL
|
|
154
|
+
| Source | Target | Command |
|
|
155
|
+
|------------|------------|-------------------------------------|
|
|
156
|
+
| SQLite | MySQL | `--format mysql` |
|
|
157
|
+
| SQLite | PostgreSQL | `--format postgresql` |
|
|
158
|
+
| MySQL | SQLite | `--from mysql --format sqlite` |
|
|
159
|
+
| PostgreSQL | SQLite | `--from postgresql --format sqlite` |
|
|
160
|
+
| MySQL | PostgreSQL | `--from mysql --format postgresql` |
|
|
161
|
+
| PostgreSQL | MySQL | `--from postgresql --format mysql` |
|
|
131
162
|
|
|
132
163
|
---
|
|
133
164
|
|
|
@@ -137,25 +168,26 @@ The tool automatically handles database-specific data type conversions:
|
|
|
137
168
|
|
|
138
169
|
### Boolean Values
|
|
139
170
|
|
|
140
|
-
| SQLite | MySQL
|
|
141
|
-
|
|
142
|
-
| 0/1
|
|
171
|
+
| SQLite | MySQL | PostgreSQL |
|
|
172
|
+
|--------|---------------|------------|
|
|
173
|
+
| 0/1 | 0/1 (TINYINT) | FALSE/TRUE |
|
|
143
174
|
|
|
144
175
|
### Binary Data
|
|
145
176
|
|
|
146
|
-
| SQLite
|
|
147
|
-
|
|
177
|
+
| SQLite | MySQL | PostgreSQL |
|
|
178
|
+
|------------|---------------|----------------|
|
|
148
179
|
| BLOB (hex) | X'hex' (BLOB) | '\xhex'::bytea |
|
|
149
180
|
|
|
150
181
|
### Identifiers
|
|
151
182
|
|
|
152
|
-
| SQLite
|
|
153
|
-
|
|
154
|
-
| "table" | \`table\` | "table"
|
|
183
|
+
| SQLite | MySQL | PostgreSQL |
|
|
184
|
+
|---------|-----------|------------|
|
|
185
|
+
| "table" | \`table\` | "table" |
|
|
155
186
|
|
|
156
187
|
### Text and Numeric Types
|
|
157
188
|
|
|
158
189
|
All databases handle TEXT, VARCHAR, INTEGER, and REAL types consistently. The tool preserves:
|
|
190
|
+
|
|
159
191
|
- Unix epoch timestamps (stored as INTEGER)
|
|
160
192
|
- UTF-8 text encoding
|
|
161
193
|
- NULL values
|
|
@@ -167,11 +199,13 @@ All databases handle TEXT, VARCHAR, INTEGER, and REAL types consistently. The to
|
|
|
167
199
|
The generated SQL is complete and self-contained. Import it directly into an **empty database**:
|
|
168
200
|
|
|
169
201
|
**SQLite:**
|
|
202
|
+
|
|
170
203
|
```bash
|
|
171
204
|
sqlite3 your-database.db < dump-sqlite.sql
|
|
172
205
|
```
|
|
173
206
|
|
|
174
207
|
**MySQL/MariaDB:**
|
|
208
|
+
|
|
175
209
|
```bash
|
|
176
210
|
# Create empty database first
|
|
177
211
|
mysql -e "CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
|
|
@@ -180,6 +214,7 @@ mysql mydb < dump-mysql.sql
|
|
|
180
214
|
```
|
|
181
215
|
|
|
182
216
|
**PostgreSQL:**
|
|
217
|
+
|
|
183
218
|
```bash
|
|
184
219
|
# Create empty database first
|
|
185
220
|
createdb mydb
|
|
@@ -193,13 +228,16 @@ Use `--on-conflict ignore` or `--on-conflict replace` when generating the dump (
|
|
|
193
228
|
## Transaction Safety
|
|
194
229
|
|
|
195
230
|
All generated SQL dumps are wrapped in database transactions:
|
|
231
|
+
|
|
196
232
|
- **MySQL/MariaDB**: `START TRANSACTION;` ... `COMMIT;`
|
|
197
233
|
- **PostgreSQL**: `BEGIN;` ... `COMMIT;`
|
|
198
234
|
- **SQLite**: `BEGIN TRANSACTION;` ... `COMMIT;`
|
|
199
235
|
|
|
200
|
-
If the import fails at any point, all changes are automatically rolled back, leaving the database in its original state.
|
|
236
|
+
If the import fails at any point, all changes are automatically rolled back, leaving the database in its original state.
|
|
237
|
+
This prevents partial imports that would leave the database in an inconsistent state.
|
|
201
238
|
|
|
202
239
|
**Benefits:**
|
|
240
|
+
|
|
203
241
|
- Atomic imports: Either all data is imported successfully or nothing is changed
|
|
204
242
|
- Safe to retry: Failed imports don't leave partial data that needs cleanup
|
|
205
243
|
- Consistent state: Database is never left in an intermediate state
|
|
@@ -243,5 +281,6 @@ PG_DATABASE=mcp_context # Default: mcp_context
|
|
|
243
281
|
## Support
|
|
244
282
|
|
|
245
283
|
For issues or questions:
|
|
284
|
+
|
|
246
285
|
- GitHub Issues: https://github.com/sin5ddd/mcp-sqlew/issues
|
|
247
286
|
- Documentation: `/docs` directory in repository
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
# Data Export/Import
|
|
2
|
+
|
|
3
|
+
> JSON-based project data migration for sharing and multi-database workflows
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
sqlew provides a complete JSON export/import system for migrating project data between databases. This is useful for:
|
|
8
|
+
|
|
9
|
+
- **Project Sharing** - Share context with team members or between machines
|
|
10
|
+
- **Database Migration** - Move projects to different sqlew databases (different machine, different DB type)
|
|
11
|
+
- **Multi-Project Consolidation** - Merge multiple project exports into one database
|
|
12
|
+
|
|
13
|
+
**⚠️ Important**: Import skips if project name already exists (default: `--skip-if-exists=true`). This is **NOT a
|
|
14
|
+
backup/restore solution**.
|
|
15
|
+
|
|
16
|
+
**For backup/restore, use `db:dump` instead**: See [Database Migration Guide](DATABASE_MIGRATION.md) for full backup
|
|
17
|
+
solutions including schema + data using SQL dumps.
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
### Export a Project
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# You have to install sqlew via npm to use CLI mode
|
|
25
|
+
cd /path/to/your/project
|
|
26
|
+
npm install sqlew
|
|
27
|
+
|
|
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
|
|
33
|
+
|
|
34
|
+
# Export to stdout (pipe to another command)
|
|
35
|
+
node node_modules/sqlew/dist/cli.js db:export --project=visualizer
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Import a Project
|
|
39
|
+
|
|
40
|
+
```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
|
+
# Import from JSON export
|
|
46
|
+
node node_modules/sqlew/dist/cli.js db:import --source=backup.json
|
|
47
|
+
|
|
48
|
+
# Import with custom project name
|
|
49
|
+
node node_modules/sqlew/dist/cli.js db:import --source=backup.json --project-name=new-name
|
|
50
|
+
|
|
51
|
+
# Dry-run validation (no actual import)
|
|
52
|
+
node node_modules/sqlew/dist/cli.js db:import --source=backup.json --dry-run
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Export Command
|
|
56
|
+
|
|
57
|
+
### Syntax
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
node node_modules/sqlew/dist/cli.js db:export [options]
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Options
|
|
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 |
|
|
71
|
+
|
|
72
|
+
### What Gets Exported
|
|
73
|
+
|
|
74
|
+
- **Master Tables** (filtered to used entries only):
|
|
75
|
+
- Agents (m_agents)
|
|
76
|
+
- Context keys (m_context_keys)
|
|
77
|
+
- Files (m_files)
|
|
78
|
+
- Tags (m_tags)
|
|
79
|
+
- Scopes (m_scopes)
|
|
80
|
+
- Layers (m_layers)
|
|
81
|
+
- Project metadata (m_projects)
|
|
82
|
+
|
|
83
|
+
- **Transaction Tables** (all data for selected project):
|
|
84
|
+
- Decisions with context (t_decisions, t_decision_context)
|
|
85
|
+
- Tasks with details (t_tasks, t_task_details)
|
|
86
|
+
- File changes (t_file_changes)
|
|
87
|
+
- Constraints (t_constraints)
|
|
88
|
+
|
|
89
|
+
- **Junction Tables** (relationships):
|
|
90
|
+
- Task tags, file links, decision links, dependencies
|
|
91
|
+
- Decision tags, scopes
|
|
92
|
+
- Constraint tags
|
|
93
|
+
|
|
94
|
+
## Import Command
|
|
95
|
+
|
|
96
|
+
### Syntax
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
node node_modules/sqlew/dist/cli.js db:import --source=<file> [options]
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Options
|
|
103
|
+
|
|
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 |
|
|
112
|
+
|
|
113
|
+
### Import Process
|
|
114
|
+
|
|
115
|
+
1. **Validation** - Checks JSON format, required fields, data types
|
|
116
|
+
2. **Conflict Detection** - Checks if project name already exists
|
|
117
|
+
3. **Topological Sort** - Resolves task dependencies (circular detection)
|
|
118
|
+
4. **ID Remapping** - Creates new IDs for all imported data
|
|
119
|
+
5. **Master Table Merge** - Reuses existing agents/tags/files by name
|
|
120
|
+
6. **Transaction Import** - Imports with fresh IDs and translated foreign keys
|
|
121
|
+
7. **Junction Table Import** - Restores all relationships
|
|
122
|
+
8. **Validation** - Verifies all foreign key references
|
|
123
|
+
|
|
124
|
+
### Smart Features
|
|
125
|
+
|
|
126
|
+
**ID Remapping**:
|
|
127
|
+
|
|
128
|
+
- All imported data gets fresh auto-incremented IDs
|
|
129
|
+
- Original IDs are mapped to new IDs during transaction
|
|
130
|
+
- Foreign key references automatically updated
|
|
131
|
+
|
|
132
|
+
**Master Table Deduplication**:
|
|
133
|
+
|
|
134
|
+
- Agents, tags, scopes, files reused if they already exist (by name/path)
|
|
135
|
+
- Prevents duplicate entries for common metadata
|
|
136
|
+
- Project-scoped master tables (m_files, m_tags, m_scopes) isolated by project_id
|
|
137
|
+
|
|
138
|
+
**Dependency Resolution**:
|
|
139
|
+
|
|
140
|
+
- Task dependencies sorted topologically
|
|
141
|
+
- Circular dependency detection prevents invalid imports
|
|
142
|
+
- Dependencies always imported before dependents
|
|
143
|
+
|
|
144
|
+
**Transaction Safety**:
|
|
145
|
+
|
|
146
|
+
- All-or-nothing semantics (full rollback on any error)
|
|
147
|
+
- Idempotent operations (safe to retry on failure)
|
|
148
|
+
- Comprehensive error messages with validation details
|
|
149
|
+
|
|
150
|
+
## Installation for CLI Usage
|
|
151
|
+
|
|
152
|
+
For users who need to use export/import commands, install sqlew per-project:
|
|
153
|
+
|
|
154
|
+
```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
|
+
```
|
|
163
|
+
|
|
164
|
+
**Tip**: Add a shortcut to your `package.json` for convenience:
|
|
165
|
+
|
|
166
|
+
```json
|
|
167
|
+
{
|
|
168
|
+
"scripts": {
|
|
169
|
+
"sqlew": "node node_modules/sqlew/dist/cli.js"
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
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.
|
|
178
|
+
|
|
179
|
+
## Use Cases
|
|
180
|
+
|
|
181
|
+
### Multi-Project Single Database (Permission-Constrained Environments)
|
|
182
|
+
|
|
183
|
+
**Scenario**: You work on multiple projects but don't have permissions to create separate MySQL databases. You want to
|
|
184
|
+
consolidate all project contexts into one shared database.
|
|
185
|
+
|
|
186
|
+
**Solution**: Use export/import to merge multiple project contexts:
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
# Step 1: Export from each project's SQLite database
|
|
190
|
+
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
|
|
193
|
+
|
|
194
|
+
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
|
|
197
|
+
|
|
198
|
+
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
|
|
201
|
+
|
|
202
|
+
# Step 2: Create shared database and import all projects
|
|
203
|
+
cd ~/shared-database
|
|
204
|
+
npm install sqlew
|
|
205
|
+
|
|
206
|
+
# Configure to use single MySQL database (edit .sqlew/config.toml)
|
|
207
|
+
# [database]
|
|
208
|
+
# type = "mysql"
|
|
209
|
+
# host = "localhost"
|
|
210
|
+
# port = 3306
|
|
211
|
+
# user = "myuser"
|
|
212
|
+
# password = "mypassword"
|
|
213
|
+
# database = "shared_sqlew_db"
|
|
214
|
+
|
|
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
|
|
218
|
+
|
|
219
|
+
# Step 3: Configure each project to use shared database
|
|
220
|
+
# In each project's .mcp.json:
|
|
221
|
+
# {
|
|
222
|
+
# "mcpServers": {
|
|
223
|
+
# "sqlew": {
|
|
224
|
+
# "command": "npx",
|
|
225
|
+
# "args": ["sqlew", "--config-path=/path/to/shared-database/.sqlew/config.toml"]
|
|
226
|
+
# }
|
|
227
|
+
# }
|
|
228
|
+
# }
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
**Benefits**:
|
|
232
|
+
|
|
233
|
+
- ✅ Single database for multiple projects (saves database quota)
|
|
234
|
+
- ✅ Cross-project context visibility (search decisions across all projects)
|
|
235
|
+
- ✅ Centralized backup and maintenance
|
|
236
|
+
- ✅ Works with permission-constrained MySQL/PostgreSQL environments
|
|
237
|
+
|
|
238
|
+
**Trade-offs**:
|
|
239
|
+
|
|
240
|
+
- ⚠️ All projects share same database connection pool
|
|
241
|
+
- ⚠️ Requires manual config path in each project's .mcp.json
|
|
242
|
+
- ⚠️ Project isolation maintained via project_id, not separate databases
|
|
243
|
+
|
|
244
|
+
### Database Migration (Cross-Machine or Cross-Database)
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
# Export from source database
|
|
248
|
+
node node_modules/sqlew/dist/cli.js db:export --project=main --output=main-export.json
|
|
249
|
+
|
|
250
|
+
# Import to different database (different machine or different database type)
|
|
251
|
+
# 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
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
**Note**: Import skips if project name exists.
|
|
256
|
+
|
|
257
|
+
**For backup/restore, use `db:dump` instead**:
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
# 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
|
|
262
|
+
|
|
263
|
+
# Or simple SQLite file copy
|
|
264
|
+
cp .sqlew/sqlew.db .sqlew/backup-$(date +%Y%m%d).db
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
See `node node_modules/sqlew/dist/cli.js db:dump --help` for full backup options.
|
|
268
|
+
|
|
269
|
+
### Project Sharing
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
# Developer A: Export project
|
|
273
|
+
node node_modules/sqlew/dist/cli.js db:export --project=feature-x --output=feature-x.json
|
|
274
|
+
|
|
275
|
+
# Developer B: Import project
|
|
276
|
+
node node_modules/sqlew/dist/cli.js db:import --source=feature-x.json
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### Multi-Project Consolidation
|
|
280
|
+
|
|
281
|
+
```bash
|
|
282
|
+
# 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
|
|
285
|
+
|
|
286
|
+
# 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
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Cross-Database Migration
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
# Export from SQLite
|
|
295
|
+
node node_modules/sqlew/dist/cli.js db:export --output=data.json --db-path=.sqlew/sqlew.db
|
|
296
|
+
|
|
297
|
+
# Import to MySQL
|
|
298
|
+
node node_modules/sqlew/dist/cli.js db:import --source=data.json --db-path=mysql://localhost/sqlew
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
## Error Handling
|
|
302
|
+
|
|
303
|
+
### Common Errors
|
|
304
|
+
|
|
305
|
+
**Project Already Exists**:
|
|
306
|
+
|
|
307
|
+
```
|
|
308
|
+
Error: Project "my-project" already exists in target database
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
Solution: Use `--project-name` to specify different name, or remove existing project
|
|
312
|
+
|
|
313
|
+
**Circular Dependencies**:
|
|
314
|
+
|
|
315
|
+
```
|
|
316
|
+
Error: Circular dependency detected in task dependencies
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Solution: Fix dependency graph in source database before exporting
|
|
320
|
+
|
|
321
|
+
**Invalid Foreign Keys**:
|
|
322
|
+
|
|
323
|
+
```
|
|
324
|
+
Error: Foreign key constraint violation for task_id=123
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
Solution: Ensure all referenced entities exist in export
|
|
328
|
+
|
|
329
|
+
### Dry-Run Validation
|
|
330
|
+
|
|
331
|
+
Always test imports with `--dry-run` first:
|
|
332
|
+
|
|
333
|
+
```bash
|
|
334
|
+
node node_modules/sqlew/dist/cli.js db:import --source=data.json --dry-run
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
This validates:
|
|
338
|
+
|
|
339
|
+
- JSON format and structure
|
|
340
|
+
- Project name conflicts
|
|
341
|
+
- Task dependency cycles
|
|
342
|
+
- Foreign key references
|
|
343
|
+
- Data type correctness
|
|
344
|
+
|
|
345
|
+
## Technical Details
|
|
346
|
+
|
|
347
|
+
### Performance
|
|
348
|
+
|
|
349
|
+
- **Batch Inserts**: 10-row batches to avoid SQLite limits
|
|
350
|
+
- **Transaction Scope**: Single transaction for atomicity
|
|
351
|
+
- **Memory Efficient**: Streams large datasets
|
|
352
|
+
|
|
353
|
+
### Limitations
|
|
354
|
+
|
|
355
|
+
- **Max JSON Size**: Limited by available memory
|
|
356
|
+
- **SQLite Batch Limit**: 500 UNION ALL clauses (handled automatically)
|
|
357
|
+
- **Cross-Database**: JSON format only (no SQL dump)
|
|
358
|
+
|
|
359
|
+
### Data Integrity
|
|
360
|
+
|
|
361
|
+
- **Foreign Key Validation**: All references validated before insertion
|
|
362
|
+
- **Orphan Cleanup**: Invalid references automatically filtered
|
|
363
|
+
- **View Restoration**: Views temporarily dropped and restored during import
|
|
364
|
+
- **Idempotent Operations**: Safe to retry on network/disk failures
|
|
365
|
+
|
|
366
|
+
## Comparison with db:dump
|
|
367
|
+
|
|
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
|
|
393
|
+
|
|
394
|
+
See [Database Migration Guide](DATABASE_MIGRATION.md) for complete `db:dump` documentation.
|
|
395
|
+
|
|
396
|
+
## See Also
|
|
397
|
+
|
|
398
|
+
- [Database Migration](DATABASE_MIGRATION.md) - SQLite → MySQL/PostgreSQL migration
|
|
399
|
+
- [CHANGELOG.md](../../CHANGELOG.md#374) - v3.7.4 release notes
|
|
400
|
+
- [Architecture](../ARCHITECTURE.md) - Technical architecture overview
|