sqlew 4.0.4 → 4.1.0
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 +1805 -1762
- package/LICENSE +177 -39
- package/NOTICE +24 -0
- package/README.md +409 -390
- package/assets/claude-md-snippets/plan-mode-integration.md +17 -6
- package/assets/config.example.toml +282 -284
- package/assets/sample-agents/README.md +36 -40
- package/assets/sample-agents/sqlew-architect.md +321 -322
- package/assets/sample-agents/sqlew-researcher.md +292 -293
- package/assets/sample-agents/sqlew-scrum-master.md +286 -287
- package/assets/sample-commands/README.md +56 -57
- package/assets/sample-skills/sqlew-plan-guidance/SKILL.md +33 -26
- package/dist/cli/hooks/check-completion.d.ts +19 -0
- package/dist/cli/hooks/check-completion.d.ts.map +1 -0
- package/dist/cli/hooks/check-completion.js +104 -0
- package/dist/cli/hooks/check-completion.js.map +1 -0
- package/dist/cli/hooks/init-hooks.d.ts +35 -0
- package/dist/cli/hooks/init-hooks.d.ts.map +1 -0
- package/dist/cli/hooks/init-hooks.js +425 -0
- package/dist/cli/hooks/init-hooks.js.map +1 -0
- package/dist/cli/hooks/mark-done.d.ts +25 -0
- package/dist/cli/hooks/mark-done.d.ts.map +1 -0
- package/dist/cli/hooks/mark-done.js +128 -0
- package/dist/cli/hooks/mark-done.js.map +1 -0
- package/dist/cli/hooks/plan-id-utils.d.ts +83 -0
- package/dist/cli/hooks/plan-id-utils.d.ts.map +1 -0
- package/dist/cli/hooks/plan-id-utils.js +183 -0
- package/dist/cli/hooks/plan-id-utils.js.map +1 -0
- package/dist/cli/hooks/save.d.ts +23 -0
- package/dist/cli/hooks/save.d.ts.map +1 -0
- package/dist/cli/hooks/save.js +90 -0
- package/dist/cli/hooks/save.js.map +1 -0
- package/dist/cli/hooks/stdin-parser.d.ts +139 -0
- package/dist/cli/hooks/stdin-parser.d.ts.map +1 -0
- package/dist/cli/hooks/stdin-parser.js +127 -0
- package/dist/cli/hooks/stdin-parser.js.map +1 -0
- package/dist/cli/hooks/suggest.d.ts +19 -0
- package/dist/cli/hooks/suggest.d.ts.map +1 -0
- package/dist/cli/hooks/suggest.js +157 -0
- package/dist/cli/hooks/suggest.js.map +1 -0
- package/dist/cli/hooks/track-plan.d.ts +36 -0
- package/dist/cli/hooks/track-plan.d.ts.map +1 -0
- package/dist/cli/hooks/track-plan.js +152 -0
- package/dist/cli/hooks/track-plan.js.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +56 -16
- package/dist/cli.js.map +1 -1
- package/dist/config/global-config.d.ts +187 -0
- package/dist/config/global-config.d.ts.map +1 -0
- package/dist/config/global-config.js +206 -0
- package/dist/config/global-config.js.map +1 -0
- package/dist/config/loader.d.ts +42 -0
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/config/loader.js +96 -0
- package/dist/config/loader.js.map +1 -1
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +10 -0
- package/dist/constants.js.map +1 -1
- package/dist/database/operations/queries.d.ts.map +1 -1
- package/dist/database/operations/queries.js +11 -2
- package/dist/database/operations/queries.js.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/init-agents.js +0 -1
- package/dist/init-agents.js.map +1 -1
- package/dist/init-skills.d.ts +4 -3
- package/dist/init-skills.d.ts.map +1 -1
- package/dist/init-skills.js +10 -3
- package/dist/init-skills.js.map +1 -1
- package/dist/server/setup.d.ts +8 -0
- package/dist/server/setup.d.ts.map +1 -1
- package/dist/server/setup.js +141 -21
- package/dist/server/setup.js.map +1 -1
- package/dist/sync-agents.d.ts.map +1 -1
- package/dist/sync-agents.js +48 -3
- package/dist/sync-agents.js.map +1 -1
- package/dist/sync-commands.d.ts.map +1 -1
- package/dist/sync-commands.js +43 -3
- package/dist/sync-commands.js.map +1 -1
- package/dist/tools/constraints/actions/get.d.ts.map +1 -1
- package/dist/tools/constraints/actions/get.js +5 -8
- package/dist/tools/constraints/actions/get.js.map +1 -1
- package/dist/tools/constraints/help/help.d.ts.map +1 -1
- package/dist/tools/constraints/help/help.js +1 -6
- package/dist/tools/constraints/help/help.js.map +1 -1
- package/dist/tools/context/actions/get.d.ts.map +1 -1
- package/dist/tools/context/actions/get.js.map +1 -1
- package/dist/tools/context/actions/search-layer.d.ts.map +1 -1
- package/dist/tools/context/actions/search-layer.js +5 -3
- package/dist/tools/context/actions/search-layer.js.map +1 -1
- package/dist/tools/context/actions/set-from-policy.d.ts +2 -1
- package/dist/tools/context/actions/set-from-policy.d.ts.map +1 -1
- package/dist/tools/context/actions/set-from-policy.js.map +1 -1
- package/dist/tools/context/help/help.d.ts.map +1 -1
- package/dist/tools/context/help/help.js +1 -7
- package/dist/tools/context/help/help.js.map +1 -1
- package/dist/tools/context/internal/queries.d.ts.map +1 -1
- package/dist/tools/context/internal/queries.js +5 -2
- package/dist/tools/context/internal/queries.js.map +1 -1
- package/dist/tools/context/types.d.ts +1 -1
- package/dist/tools/context/types.d.ts.map +1 -1
- package/dist/tools/files/actions/get.d.ts.map +1 -1
- package/dist/tools/files/actions/get.js +4 -6
- package/dist/tools/files/actions/get.js.map +1 -1
- package/dist/tools/files/help/help.d.ts.map +1 -1
- package/dist/tools/files/help/help.js +1 -6
- package/dist/tools/files/help/help.js.map +1 -1
- package/dist/tools/suggest/help/constraint-help.d.ts.map +1 -1
- package/dist/tools/suggest/help/constraint-help.js +0 -2
- package/dist/tools/suggest/help/constraint-help.js.map +1 -1
- package/dist/tools/suggest/internal/constraint-queries.d.ts.map +1 -1
- package/dist/tools/suggest/internal/constraint-queries.js +12 -5
- package/dist/tools/suggest/internal/constraint-queries.js.map +1 -1
- package/dist/tools/suggest/internal/queries.js +2 -2
- package/dist/tools/suggest/internal/queries.js.map +1 -1
- package/dist/tools/tasks/help/help.d.ts.map +1 -1
- package/dist/tools/tasks/help/help.js +0 -6
- package/dist/tools/tasks/help/help.js.map +1 -1
- package/dist/tools/tasks/help/use-case.d.ts.map +1 -1
- package/dist/tools/tasks/help/use-case.js +0 -1
- package/dist/tools/tasks/help/use-case.js.map +1 -1
- package/dist/tools/tasks/watcher/status.d.ts.map +1 -1
- package/dist/tools/tasks/watcher/status.js +5 -1
- package/dist/tools/tasks/watcher/status.js.map +1 -1
- package/dist/types/decision/params.d.ts +7 -6
- package/dist/types/decision/params.d.ts.map +1 -1
- package/dist/types/decision/templates.d.ts +3 -2
- package/dist/types/decision/templates.d.ts.map +1 -1
- package/dist/types/view-entities.d.ts +2 -1
- package/dist/types/view-entities.d.ts.map +1 -1
- package/dist/types.d.ts +19 -11
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/enum-converter.d.ts +72 -0
- package/dist/utils/enum-converter.d.ts.map +1 -0
- package/dist/utils/enum-converter.js +76 -0
- package/dist/utils/enum-converter.js.map +1 -0
- package/dist/utils/hook-queue.d.ts +81 -0
- package/dist/utils/hook-queue.d.ts.map +1 -0
- package/dist/utils/hook-queue.js +156 -0
- package/dist/utils/hook-queue.js.map +1 -0
- package/dist/utils/project-root.d.ts +9 -2
- package/dist/utils/project-root.d.ts.map +1 -1
- package/dist/utils/project-root.js +16 -2
- package/dist/utils/project-root.js.map +1 -1
- package/dist/utils/tag-parser.d.ts.map +1 -1
- package/dist/utils/tag-parser.js +6 -0
- package/dist/utils/tag-parser.js.map +1 -1
- package/dist/utils/validators.d.ts +1 -1
- package/dist/utils/validators.d.ts.map +1 -1
- package/dist/utils/validators.js +1 -1
- package/dist/utils/validators.js.map +1 -1
- package/dist/utils/vcs-adapter.d.ts +44 -0
- package/dist/utils/vcs-adapter.d.ts.map +1 -1
- package/dist/utils/vcs-adapter.js +88 -0
- package/dist/utils/vcs-adapter.js.map +1 -1
- package/dist/utils/view-queries.d.ts.map +1 -1
- package/dist/utils/view-queries.js +9 -19
- package/dist/utils/view-queries.js.map +1 -1
- package/dist/watcher/base-watcher.d.ts +69 -0
- package/dist/watcher/base-watcher.d.ts.map +1 -0
- package/dist/watcher/base-watcher.js +130 -0
- package/dist/watcher/base-watcher.js.map +1 -0
- package/dist/watcher/index.d.ts +3 -0
- package/dist/watcher/index.d.ts.map +1 -1
- package/dist/watcher/index.js +2 -0
- package/dist/watcher/index.js.map +1 -1
- package/dist/watcher/queue-watcher.d.ts +64 -0
- package/dist/watcher/queue-watcher.d.ts.map +1 -0
- package/dist/watcher/queue-watcher.js +187 -0
- package/dist/watcher/queue-watcher.js.map +1 -0
- package/docs/ADR_CONCEPTS.md +140 -0
- package/docs/CONFIGURATION.md +922 -925
- package/docs/CROSS_DATABASE.md +153 -0
- package/docs/DATABASE_AUTH.md +70 -356
- package/docs/HOOKS_GUIDE.md +159 -0
- package/docs/SLASH_COMMANDS.md +329 -337
- package/docs/TASK_SYSTEM_DEPRECATED.md +88 -0
- package/docs/changelogs/CHANGELOG_ARCHIVE_v3.4_and_older.md +293 -296
- package/docs/cli/DATA_EXPORT_IMPORT.md +699 -700
- package/docs/cli/README.md +276 -277
- package/package.json +123 -119
- package/docs/ACCEPTANCE_CRITERIA.md +0 -625
- package/docs/AI_AGENT_GUIDE.md +0 -198
- package/docs/ARCHITECTURE.md +0 -167
- package/docs/AUTO_FILE_TRACKING.md +0 -841
- package/docs/BATCH_VALIDATION.md +0 -617
- package/docs/BEST_PRACTICES.md +0 -168
- package/docs/CONSTRAINT_INTELLIGENCE.md +0 -339
- package/docs/DECISION_CONTEXT.md +0 -675
- package/docs/DECISION_INTELLIGENCE.md +0 -605
- package/docs/GIT_AWARE_AUTO_COMPLETE.md +0 -646
- package/docs/MIGRATION_GUIDE_V3.9.0.md +0 -371
- package/docs/SHARED_CONCEPTS.md +0 -225
- package/docs/SPECIALIZED_AGENTS.md +0 -126
- package/docs/TASK_ACTIONS.md +0 -1177
- package/docs/TASK_OVERVIEW.md +0 -452
- package/docs/TASK_PRUNING.md +0 -594
- package/docs/TOOL_REFERENCE.md +0 -1077
- package/docs/TOOL_SELECTION.md +0 -83
- package/docs/WORKFLOWS.md +0 -941
|
@@ -1,700 +1,699 @@
|
|
|
1
|
-
# Data Export/Import
|
|
2
|
-
|
|
3
|
-
> JSON-based project data migration for sharing and multi-database workflows
|
|
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
|
-
|
|
13
|
-
## Overview
|
|
14
|
-
|
|
15
|
-
sqlew provides a complete JSON export/import system for migrating project data between databases. This is useful for:
|
|
16
|
-
|
|
17
|
-
- **Project Sharing** - Share context with team members or between machines
|
|
18
|
-
- **Database Migration** - Move projects to different sqlew databases (different machine, different DB type)
|
|
19
|
-
- **Multi-Project Consolidation** - Merge multiple project exports into one database
|
|
20
|
-
|
|
21
|
-
**⚠️ Important**: Import skips if project name already exists (default: `--skip-if-exists=true`). This is **NOT a
|
|
22
|
-
backup/restore solution**.
|
|
23
|
-
|
|
24
|
-
**For backup/restore, use `db:dump` instead**: See [Database Migration Guide](DATABASE_MIGRATION.md) for full backup
|
|
25
|
-
solutions including schema + data using SQL dumps.
|
|
26
|
-
|
|
27
|
-
## Quick Start
|
|
28
|
-
|
|
29
|
-
### Export a Project
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
# Export all projects (no installation required!)
|
|
33
|
-
npx sqlew db:export backup.json
|
|
34
|
-
|
|
35
|
-
# Export specific project to file
|
|
36
|
-
npx sqlew db:export backup.json project=my-project
|
|
37
|
-
|
|
38
|
-
# Export to stdout (pipe to another command)
|
|
39
|
-
npx sqlew db:export project=visualizer
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
### Import a Project
|
|
43
|
-
|
|
44
|
-
```bash
|
|
45
|
-
# Import from JSON export
|
|
46
|
-
npx sqlew db:import backup.json
|
|
47
|
-
|
|
48
|
-
# Import with custom project name
|
|
49
|
-
npx sqlew db:import backup.json project-name=new-name
|
|
50
|
-
|
|
51
|
-
# Dry-run validation (no actual import)
|
|
52
|
-
npx sqlew db:import backup.json dry-run=true
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
## Export Command
|
|
56
|
-
|
|
57
|
-
### Syntax
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
npx sqlew db:export [output-file] [key=value ...]
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
### Options
|
|
64
|
-
|
|
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 |
|
|
70
|
-
|
|
71
|
-
### What Gets Exported
|
|
72
|
-
|
|
73
|
-
- **Master Tables** (filtered to used entries only):
|
|
74
|
-
- Agents (m_agents)
|
|
75
|
-
- Context keys (m_context_keys)
|
|
76
|
-
- Files (m_files)
|
|
77
|
-
- Tags (m_tags)
|
|
78
|
-
- Scopes (m_scopes)
|
|
79
|
-
- Layers (m_layers)
|
|
80
|
-
- Project metadata (m_projects)
|
|
81
|
-
|
|
82
|
-
- **Transaction Tables** (all data for selected project):
|
|
83
|
-
- Decisions with context (t_decisions, t_decision_context)
|
|
84
|
-
- Tasks with details (t_tasks, t_task_details)
|
|
85
|
-
- File changes (t_file_changes)
|
|
86
|
-
- Constraints (t_constraints)
|
|
87
|
-
|
|
88
|
-
- **Junction Tables** (relationships):
|
|
89
|
-
- Task tags, file links, decision links, dependencies
|
|
90
|
-
- Decision tags, scopes
|
|
91
|
-
- Constraint tags
|
|
92
|
-
|
|
93
|
-
## Import Command
|
|
94
|
-
|
|
95
|
-
### Syntax
|
|
96
|
-
|
|
97
|
-
```bash
|
|
98
|
-
npx sqlew db:import <source-file> [key=value ...]
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
### Options
|
|
102
|
-
|
|
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 |
|
|
111
|
-
|
|
112
|
-
### Import Process
|
|
113
|
-
|
|
114
|
-
1. **Validation** - Checks JSON format, required fields, data types
|
|
115
|
-
2. **Conflict Detection** - Checks if project name already exists
|
|
116
|
-
3. **Topological Sort** - Resolves task dependencies (circular detection)
|
|
117
|
-
4. **ID Remapping** - Creates new IDs for all imported data
|
|
118
|
-
5. **Master Table Merge** - Reuses existing agents/tags/files by name
|
|
119
|
-
6. **Transaction Import** - Imports with fresh IDs and translated foreign keys
|
|
120
|
-
7. **Junction Table Import** - Restores all relationships
|
|
121
|
-
8. **Validation** - Verifies all foreign key references
|
|
122
|
-
|
|
123
|
-
### Smart Features
|
|
124
|
-
|
|
125
|
-
**ID Remapping**:
|
|
126
|
-
|
|
127
|
-
- All imported data gets fresh auto-incremented IDs
|
|
128
|
-
- Original IDs are mapped to new IDs during transaction
|
|
129
|
-
- Foreign key references automatically updated
|
|
130
|
-
|
|
131
|
-
**Master Table Deduplication**:
|
|
132
|
-
|
|
133
|
-
- Agents, tags, scopes, files reused if they already exist (by name/path)
|
|
134
|
-
- Prevents duplicate entries for common metadata
|
|
135
|
-
- Project-scoped master tables (m_files, m_tags, m_scopes) isolated by project_id
|
|
136
|
-
|
|
137
|
-
**Dependency Resolution**:
|
|
138
|
-
|
|
139
|
-
- Task dependencies sorted topologically
|
|
140
|
-
- Circular dependency detection prevents invalid imports
|
|
141
|
-
- Dependencies always imported before dependents
|
|
142
|
-
|
|
143
|
-
**Transaction Safety**:
|
|
144
|
-
|
|
145
|
-
- All-or-nothing semantics (full rollback on any error)
|
|
146
|
-
- Idempotent operations (safe to retry on failure)
|
|
147
|
-
- Comprehensive error messages with validation details
|
|
148
|
-
|
|
149
|
-
## CLI Usage
|
|
150
|
-
|
|
151
|
-
**No installation required!** The unified entry point allows direct use via npx:
|
|
152
|
-
|
|
153
|
-
```bash
|
|
154
|
-
# Export data
|
|
155
|
-
npx sqlew db:export backup.json
|
|
156
|
-
|
|
157
|
-
# Import data
|
|
158
|
-
npx sqlew db:import backup.json
|
|
159
|
-
|
|
160
|
-
# SQL dump (same-database backup)
|
|
161
|
-
npx sqlew db:dump sqlite backup.sql
|
|
162
|
-
```
|
|
163
|
-
|
|
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
|
|
167
|
-
|
|
168
|
-
## Use Cases
|
|
169
|
-
|
|
170
|
-
### Multi-Project Single Database (Permission-Constrained Environments)
|
|
171
|
-
|
|
172
|
-
**Scenario**: You work on multiple projects but don't have permissions to create separate MySQL databases. You want to
|
|
173
|
-
consolidate all project contexts into one shared database.
|
|
174
|
-
|
|
175
|
-
**Solution**: Use export/import to merge multiple project contexts:
|
|
176
|
-
|
|
177
|
-
```bash
|
|
178
|
-
# Step 1: Export from each project's SQLite database
|
|
179
|
-
cd ~/project-a
|
|
180
|
-
npx sqlew db:export /tmp/project-a.json project=project-a
|
|
181
|
-
|
|
182
|
-
cd ~/project-b
|
|
183
|
-
npx sqlew db:export /tmp/project-b.json project=project-b
|
|
184
|
-
|
|
185
|
-
cd ~/project-c
|
|
186
|
-
npx sqlew db:export /tmp/project-c.json project=project-c
|
|
187
|
-
|
|
188
|
-
# Step 2: Create shared database and import all projects
|
|
189
|
-
cd ~/shared-database
|
|
190
|
-
|
|
191
|
-
# Configure to use single MySQL database (edit .sqlew/config.toml)
|
|
192
|
-
# [database]
|
|
193
|
-
# type = "mysql"
|
|
194
|
-
# host = "localhost"
|
|
195
|
-
# port = 3306
|
|
196
|
-
# user = "myuser"
|
|
197
|
-
# password = "mypassword"
|
|
198
|
-
# database = "shared_sqlew_db"
|
|
199
|
-
|
|
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
|
|
203
|
-
|
|
204
|
-
# Step 3: Configure each project to use shared database
|
|
205
|
-
# In each project's .mcp.json:
|
|
206
|
-
# {
|
|
207
|
-
# "mcpServers": {
|
|
208
|
-
# "sqlew": {
|
|
209
|
-
# "command": "npx",
|
|
210
|
-
# "args": ["sqlew", "--config-path=/path/to/shared-database/.sqlew/config.toml"]
|
|
211
|
-
# }
|
|
212
|
-
# }
|
|
213
|
-
# }
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
**Benefits**:
|
|
217
|
-
|
|
218
|
-
- ✅ Single database for multiple projects (saves database quota)
|
|
219
|
-
- ✅ Cross-project context visibility (search decisions across all projects)
|
|
220
|
-
- ✅ Centralized backup and maintenance
|
|
221
|
-
- ✅ Works with permission-constrained MySQL/PostgreSQL environments
|
|
222
|
-
|
|
223
|
-
**Trade-offs**:
|
|
224
|
-
|
|
225
|
-
- ⚠️ All projects share same database connection pool
|
|
226
|
-
- ⚠️ Requires manual config path in each project's .mcp.json
|
|
227
|
-
- ⚠️ Project isolation maintained via project_id, not separate databases
|
|
228
|
-
|
|
229
|
-
### Database Migration (Cross-Machine or Cross-Database)
|
|
230
|
-
|
|
231
|
-
```bash
|
|
232
|
-
# Export from source database
|
|
233
|
-
npx sqlew db:export main-export.json project=main
|
|
234
|
-
|
|
235
|
-
# Import to different database (different machine or different database type)
|
|
236
|
-
# This works because the project doesn't exist in the target database yet
|
|
237
|
-
npx sqlew db:import main-export.json db-path=/path/to/new/database.db
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
**Note**: Import skips if project name exists.
|
|
241
|
-
|
|
242
|
-
**For backup/restore, use `db:dump` instead**:
|
|
243
|
-
|
|
244
|
-
```bash
|
|
245
|
-
# Backup with SQL dump (preserves schema + data)
|
|
246
|
-
npx sqlew db:dump sqlite backup-$(date +%Y%m%d).sql
|
|
247
|
-
|
|
248
|
-
# Or simple SQLite file copy
|
|
249
|
-
cp .sqlew/sqlew.db .sqlew/backup-$(date +%Y%m%d).db
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
See `npx sqlew db:dump --help` for full backup options.
|
|
253
|
-
|
|
254
|
-
### Project Sharing
|
|
255
|
-
|
|
256
|
-
```bash
|
|
257
|
-
# Developer A: Export project
|
|
258
|
-
npx sqlew db:export feature-x.json project=feature-x
|
|
259
|
-
|
|
260
|
-
# Developer B: Import project
|
|
261
|
-
npx sqlew db:import feature-x.json
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
### Multi-Project Consolidation
|
|
265
|
-
|
|
266
|
-
```bash
|
|
267
|
-
# Export from different databases
|
|
268
|
-
npx sqlew db:export vis.json project=visualizer
|
|
269
|
-
npx sqlew db:export api.json project=api
|
|
270
|
-
|
|
271
|
-
# Import to single database
|
|
272
|
-
npx sqlew db:import vis.json
|
|
273
|
-
npx sqlew db:import api.json
|
|
274
|
-
```
|
|
275
|
-
|
|
276
|
-
### Cross-Database Migration
|
|
277
|
-
|
|
278
|
-
```bash
|
|
279
|
-
# Export from SQLite
|
|
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
|
|
565
|
-
|
|
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
|
-
---
|
|
601
|
-
|
|
602
|
-
## Error Handling
|
|
603
|
-
|
|
604
|
-
### Common Errors
|
|
605
|
-
|
|
606
|
-
**Project Already Exists**:
|
|
607
|
-
|
|
608
|
-
```
|
|
609
|
-
Error: Project "my-project" already exists in target database
|
|
610
|
-
```
|
|
611
|
-
|
|
612
|
-
Solution: Use `--project-name` to specify different name, or remove existing project
|
|
613
|
-
|
|
614
|
-
**Circular Dependencies**:
|
|
615
|
-
|
|
616
|
-
```
|
|
617
|
-
Error: Circular dependency detected in task dependencies
|
|
618
|
-
```
|
|
619
|
-
|
|
620
|
-
Solution: Fix dependency graph in source database before exporting
|
|
621
|
-
|
|
622
|
-
**Invalid Foreign Keys**:
|
|
623
|
-
|
|
624
|
-
```
|
|
625
|
-
Error: Foreign key constraint violation for task_id=123
|
|
626
|
-
```
|
|
627
|
-
|
|
628
|
-
Solution: Ensure all referenced entities exist in export
|
|
629
|
-
|
|
630
|
-
### Dry-Run Validation
|
|
631
|
-
|
|
632
|
-
Always test imports with `dry-run=true` first:
|
|
633
|
-
|
|
634
|
-
```bash
|
|
635
|
-
npx sqlew db:import data.json dry-run=true
|
|
636
|
-
```
|
|
637
|
-
|
|
638
|
-
This validates:
|
|
639
|
-
|
|
640
|
-
- JSON format and structure
|
|
641
|
-
- Project name conflicts
|
|
642
|
-
- Task dependency cycles
|
|
643
|
-
- Foreign key references
|
|
644
|
-
- Data type correctness
|
|
645
|
-
|
|
646
|
-
## Technical Details
|
|
647
|
-
|
|
648
|
-
### Performance
|
|
649
|
-
|
|
650
|
-
- **Batch Inserts**: 10-row batches to avoid SQLite limits
|
|
651
|
-
- **Transaction Scope**: Single transaction for atomicity
|
|
652
|
-
- **Memory Efficient**: Streams large datasets
|
|
653
|
-
|
|
654
|
-
### Limitations
|
|
655
|
-
|
|
656
|
-
- **Max JSON Size**: Limited by available memory
|
|
657
|
-
- **SQLite Batch Limit**: 500 UNION ALL clauses (handled automatically)
|
|
658
|
-
- **Cross-Database**: JSON format only (no SQL dump)
|
|
659
|
-
|
|
660
|
-
### Data Integrity
|
|
661
|
-
|
|
662
|
-
- **Foreign Key Validation**: All references validated before insertion
|
|
663
|
-
- **Orphan Cleanup**: Invalid references automatically filtered
|
|
664
|
-
- **View Restoration**: Views temporarily dropped and restored during import
|
|
665
|
-
- **Idempotent Operations**: Safe to retry on network/disk failures
|
|
666
|
-
|
|
667
|
-
## Comparison with db:dump
|
|
668
|
-
|
|
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)
|
|
693
|
-
|
|
694
|
-
See [Database Migration Guide](DATABASE_MIGRATION.md) for complete `db:dump` documentation.
|
|
695
|
-
|
|
696
|
-
## See Also
|
|
697
|
-
|
|
698
|
-
- [Database Migration](DATABASE_MIGRATION.md) - SQLite → MySQL/PostgreSQL migration
|
|
699
|
-
- [CHANGELOG.md](../../CHANGELOG.md#374) - v3.7.4 release notes
|
|
700
|
-
- [Architecture](../ARCHITECTURE.md) - Technical architecture overview
|
|
1
|
+
# Data Export/Import
|
|
2
|
+
|
|
3
|
+
> JSON-based project data migration for sharing and multi-database workflows
|
|
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
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
sqlew provides a complete JSON export/import system for migrating project data between databases. This is useful for:
|
|
16
|
+
|
|
17
|
+
- **Project Sharing** - Share context with team members or between machines
|
|
18
|
+
- **Database Migration** - Move projects to different sqlew databases (different machine, different DB type)
|
|
19
|
+
- **Multi-Project Consolidation** - Merge multiple project exports into one database
|
|
20
|
+
|
|
21
|
+
**⚠️ Important**: Import skips if project name already exists (default: `--skip-if-exists=true`). This is **NOT a
|
|
22
|
+
backup/restore solution**.
|
|
23
|
+
|
|
24
|
+
**For backup/restore, use `db:dump` instead**: See [Database Migration Guide](DATABASE_MIGRATION.md) for full backup
|
|
25
|
+
solutions including schema + data using SQL dumps.
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
### Export a Project
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# Export all projects (no installation required!)
|
|
33
|
+
npx sqlew db:export backup.json
|
|
34
|
+
|
|
35
|
+
# Export specific project to file
|
|
36
|
+
npx sqlew db:export backup.json project=my-project
|
|
37
|
+
|
|
38
|
+
# Export to stdout (pipe to another command)
|
|
39
|
+
npx sqlew db:export project=visualizer
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Import a Project
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# Import from JSON export
|
|
46
|
+
npx sqlew db:import backup.json
|
|
47
|
+
|
|
48
|
+
# Import with custom project name
|
|
49
|
+
npx sqlew db:import backup.json project-name=new-name
|
|
50
|
+
|
|
51
|
+
# Dry-run validation (no actual import)
|
|
52
|
+
npx sqlew db:import backup.json dry-run=true
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Export Command
|
|
56
|
+
|
|
57
|
+
### Syntax
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npx sqlew db:export [output-file] [key=value ...]
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Options
|
|
64
|
+
|
|
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 |
|
|
70
|
+
|
|
71
|
+
### What Gets Exported
|
|
72
|
+
|
|
73
|
+
- **Master Tables** (filtered to used entries only):
|
|
74
|
+
- Agents (m_agents)
|
|
75
|
+
- Context keys (m_context_keys)
|
|
76
|
+
- Files (m_files)
|
|
77
|
+
- Tags (m_tags)
|
|
78
|
+
- Scopes (m_scopes)
|
|
79
|
+
- Layers (m_layers)
|
|
80
|
+
- Project metadata (m_projects)
|
|
81
|
+
|
|
82
|
+
- **Transaction Tables** (all data for selected project):
|
|
83
|
+
- Decisions with context (t_decisions, t_decision_context)
|
|
84
|
+
- Tasks with details (t_tasks, t_task_details)
|
|
85
|
+
- File changes (t_file_changes)
|
|
86
|
+
- Constraints (t_constraints)
|
|
87
|
+
|
|
88
|
+
- **Junction Tables** (relationships):
|
|
89
|
+
- Task tags, file links, decision links, dependencies
|
|
90
|
+
- Decision tags, scopes
|
|
91
|
+
- Constraint tags
|
|
92
|
+
|
|
93
|
+
## Import Command
|
|
94
|
+
|
|
95
|
+
### Syntax
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
npx sqlew db:import <source-file> [key=value ...]
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Options
|
|
102
|
+
|
|
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 |
|
|
111
|
+
|
|
112
|
+
### Import Process
|
|
113
|
+
|
|
114
|
+
1. **Validation** - Checks JSON format, required fields, data types
|
|
115
|
+
2. **Conflict Detection** - Checks if project name already exists
|
|
116
|
+
3. **Topological Sort** - Resolves task dependencies (circular detection)
|
|
117
|
+
4. **ID Remapping** - Creates new IDs for all imported data
|
|
118
|
+
5. **Master Table Merge** - Reuses existing agents/tags/files by name
|
|
119
|
+
6. **Transaction Import** - Imports with fresh IDs and translated foreign keys
|
|
120
|
+
7. **Junction Table Import** - Restores all relationships
|
|
121
|
+
8. **Validation** - Verifies all foreign key references
|
|
122
|
+
|
|
123
|
+
### Smart Features
|
|
124
|
+
|
|
125
|
+
**ID Remapping**:
|
|
126
|
+
|
|
127
|
+
- All imported data gets fresh auto-incremented IDs
|
|
128
|
+
- Original IDs are mapped to new IDs during transaction
|
|
129
|
+
- Foreign key references automatically updated
|
|
130
|
+
|
|
131
|
+
**Master Table Deduplication**:
|
|
132
|
+
|
|
133
|
+
- Agents, tags, scopes, files reused if they already exist (by name/path)
|
|
134
|
+
- Prevents duplicate entries for common metadata
|
|
135
|
+
- Project-scoped master tables (m_files, m_tags, m_scopes) isolated by project_id
|
|
136
|
+
|
|
137
|
+
**Dependency Resolution**:
|
|
138
|
+
|
|
139
|
+
- Task dependencies sorted topologically
|
|
140
|
+
- Circular dependency detection prevents invalid imports
|
|
141
|
+
- Dependencies always imported before dependents
|
|
142
|
+
|
|
143
|
+
**Transaction Safety**:
|
|
144
|
+
|
|
145
|
+
- All-or-nothing semantics (full rollback on any error)
|
|
146
|
+
- Idempotent operations (safe to retry on failure)
|
|
147
|
+
- Comprehensive error messages with validation details
|
|
148
|
+
|
|
149
|
+
## CLI Usage
|
|
150
|
+
|
|
151
|
+
**No installation required!** The unified entry point allows direct use via npx:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
# Export data
|
|
155
|
+
npx sqlew db:export backup.json
|
|
156
|
+
|
|
157
|
+
# Import data
|
|
158
|
+
npx sqlew db:import backup.json
|
|
159
|
+
|
|
160
|
+
# SQL dump (same-database backup)
|
|
161
|
+
npx sqlew db:dump sqlite backup.sql
|
|
162
|
+
```
|
|
163
|
+
|
|
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
|
|
167
|
+
|
|
168
|
+
## Use Cases
|
|
169
|
+
|
|
170
|
+
### Multi-Project Single Database (Permission-Constrained Environments)
|
|
171
|
+
|
|
172
|
+
**Scenario**: You work on multiple projects but don't have permissions to create separate MySQL databases. You want to
|
|
173
|
+
consolidate all project contexts into one shared database.
|
|
174
|
+
|
|
175
|
+
**Solution**: Use export/import to merge multiple project contexts:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
# Step 1: Export from each project's SQLite database
|
|
179
|
+
cd ~/project-a
|
|
180
|
+
npx sqlew db:export /tmp/project-a.json project=project-a
|
|
181
|
+
|
|
182
|
+
cd ~/project-b
|
|
183
|
+
npx sqlew db:export /tmp/project-b.json project=project-b
|
|
184
|
+
|
|
185
|
+
cd ~/project-c
|
|
186
|
+
npx sqlew db:export /tmp/project-c.json project=project-c
|
|
187
|
+
|
|
188
|
+
# Step 2: Create shared database and import all projects
|
|
189
|
+
cd ~/shared-database
|
|
190
|
+
|
|
191
|
+
# Configure to use single MySQL database (edit .sqlew/config.toml)
|
|
192
|
+
# [database]
|
|
193
|
+
# type = "mysql"
|
|
194
|
+
# host = "localhost"
|
|
195
|
+
# port = 3306
|
|
196
|
+
# user = "myuser"
|
|
197
|
+
# password = "mypassword"
|
|
198
|
+
# database = "shared_sqlew_db"
|
|
199
|
+
|
|
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
|
|
203
|
+
|
|
204
|
+
# Step 3: Configure each project to use shared database
|
|
205
|
+
# In each project's .mcp.json:
|
|
206
|
+
# {
|
|
207
|
+
# "mcpServers": {
|
|
208
|
+
# "sqlew": {
|
|
209
|
+
# "command": "npx",
|
|
210
|
+
# "args": ["sqlew", "--config-path=/path/to/shared-database/.sqlew/config.toml"]
|
|
211
|
+
# }
|
|
212
|
+
# }
|
|
213
|
+
# }
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
**Benefits**:
|
|
217
|
+
|
|
218
|
+
- ✅ Single database for multiple projects (saves database quota)
|
|
219
|
+
- ✅ Cross-project context visibility (search decisions across all projects)
|
|
220
|
+
- ✅ Centralized backup and maintenance
|
|
221
|
+
- ✅ Works with permission-constrained MySQL/PostgreSQL environments
|
|
222
|
+
|
|
223
|
+
**Trade-offs**:
|
|
224
|
+
|
|
225
|
+
- ⚠️ All projects share same database connection pool
|
|
226
|
+
- ⚠️ Requires manual config path in each project's .mcp.json
|
|
227
|
+
- ⚠️ Project isolation maintained via project_id, not separate databases
|
|
228
|
+
|
|
229
|
+
### Database Migration (Cross-Machine or Cross-Database)
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
# Export from source database
|
|
233
|
+
npx sqlew db:export main-export.json project=main
|
|
234
|
+
|
|
235
|
+
# Import to different database (different machine or different database type)
|
|
236
|
+
# This works because the project doesn't exist in the target database yet
|
|
237
|
+
npx sqlew db:import main-export.json db-path=/path/to/new/database.db
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
**Note**: Import skips if project name exists.
|
|
241
|
+
|
|
242
|
+
**For backup/restore, use `db:dump` instead**:
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
# Backup with SQL dump (preserves schema + data)
|
|
246
|
+
npx sqlew db:dump sqlite backup-$(date +%Y%m%d).sql
|
|
247
|
+
|
|
248
|
+
# Or simple SQLite file copy
|
|
249
|
+
cp .sqlew/sqlew.db .sqlew/backup-$(date +%Y%m%d).db
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
See `npx sqlew db:dump --help` for full backup options.
|
|
253
|
+
|
|
254
|
+
### Project Sharing
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
# Developer A: Export project
|
|
258
|
+
npx sqlew db:export feature-x.json project=feature-x
|
|
259
|
+
|
|
260
|
+
# Developer B: Import project
|
|
261
|
+
npx sqlew db:import feature-x.json
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### Multi-Project Consolidation
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
# Export from different databases
|
|
268
|
+
npx sqlew db:export vis.json project=visualizer
|
|
269
|
+
npx sqlew db:export api.json project=api
|
|
270
|
+
|
|
271
|
+
# Import to single database
|
|
272
|
+
npx sqlew db:import vis.json
|
|
273
|
+
npx sqlew db:import api.json
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Cross-Database Migration
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
# Export from SQLite
|
|
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
|
|
565
|
+
|
|
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
|
+
---
|
|
601
|
+
|
|
602
|
+
## Error Handling
|
|
603
|
+
|
|
604
|
+
### Common Errors
|
|
605
|
+
|
|
606
|
+
**Project Already Exists**:
|
|
607
|
+
|
|
608
|
+
```
|
|
609
|
+
Error: Project "my-project" already exists in target database
|
|
610
|
+
```
|
|
611
|
+
|
|
612
|
+
Solution: Use `--project-name` to specify different name, or remove existing project
|
|
613
|
+
|
|
614
|
+
**Circular Dependencies**:
|
|
615
|
+
|
|
616
|
+
```
|
|
617
|
+
Error: Circular dependency detected in task dependencies
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
Solution: Fix dependency graph in source database before exporting
|
|
621
|
+
|
|
622
|
+
**Invalid Foreign Keys**:
|
|
623
|
+
|
|
624
|
+
```
|
|
625
|
+
Error: Foreign key constraint violation for task_id=123
|
|
626
|
+
```
|
|
627
|
+
|
|
628
|
+
Solution: Ensure all referenced entities exist in export
|
|
629
|
+
|
|
630
|
+
### Dry-Run Validation
|
|
631
|
+
|
|
632
|
+
Always test imports with `dry-run=true` first:
|
|
633
|
+
|
|
634
|
+
```bash
|
|
635
|
+
npx sqlew db:import data.json dry-run=true
|
|
636
|
+
```
|
|
637
|
+
|
|
638
|
+
This validates:
|
|
639
|
+
|
|
640
|
+
- JSON format and structure
|
|
641
|
+
- Project name conflicts
|
|
642
|
+
- Task dependency cycles
|
|
643
|
+
- Foreign key references
|
|
644
|
+
- Data type correctness
|
|
645
|
+
|
|
646
|
+
## Technical Details
|
|
647
|
+
|
|
648
|
+
### Performance
|
|
649
|
+
|
|
650
|
+
- **Batch Inserts**: 10-row batches to avoid SQLite limits
|
|
651
|
+
- **Transaction Scope**: Single transaction for atomicity
|
|
652
|
+
- **Memory Efficient**: Streams large datasets
|
|
653
|
+
|
|
654
|
+
### Limitations
|
|
655
|
+
|
|
656
|
+
- **Max JSON Size**: Limited by available memory
|
|
657
|
+
- **SQLite Batch Limit**: 500 UNION ALL clauses (handled automatically)
|
|
658
|
+
- **Cross-Database**: JSON format only (no SQL dump)
|
|
659
|
+
|
|
660
|
+
### Data Integrity
|
|
661
|
+
|
|
662
|
+
- **Foreign Key Validation**: All references validated before insertion
|
|
663
|
+
- **Orphan Cleanup**: Invalid references automatically filtered
|
|
664
|
+
- **View Restoration**: Views temporarily dropped and restored during import
|
|
665
|
+
- **Idempotent Operations**: Safe to retry on network/disk failures
|
|
666
|
+
|
|
667
|
+
## Comparison with db:dump
|
|
668
|
+
|
|
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)
|
|
693
|
+
|
|
694
|
+
See [Database Migration Guide](DATABASE_MIGRATION.md) for complete `db:dump` documentation.
|
|
695
|
+
|
|
696
|
+
## See Also
|
|
697
|
+
|
|
698
|
+
- [Database Migration](DATABASE_MIGRATION.md) - SQLite → MySQL/PostgreSQL migration
|
|
699
|
+
- [CHANGELOG.md](../../CHANGELOG.md#374) - v3.7.4 release notes
|