sqlew 5.0.7 → 5.0.8
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/README.md +100 -242
- package/dist/cli/hooks/pr-adr.d.ts +22 -0
- package/dist/cli/hooks/pr-adr.d.ts.map +1 -0
- package/dist/cli/hooks/pr-adr.js +72 -0
- package/dist/cli/hooks/pr-adr.js.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +8 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/docs/ADR_CONCEPTS.md +66 -58
- package/docs/CLI_USAGE.md +472 -0
- package/docs/CONFIGURATION.md +152 -922
- package/docs/CROSS_DATABASE.md +1 -88
- package/docs/DATABASE_AUTH.md +24 -47
- package/docs/HOOKS_GUIDE.md +40 -112
- package/docs/MIGRATION_TO_SAAS.md +1 -1
- package/package.json +1 -1
- package/docs/HOW_TO_UNINSTALL.md +0 -199
- package/docs/MIGRATION_CLEANUP_GUIDE.md +0 -212
- package/docs/SLASH_COMMANDS.md +0 -329
- package/docs/cli/DATABASE_MIGRATION.md +0 -290
- package/docs/cli/DATA_EXPORT_IMPORT.md +0 -701
- package/docs/cli/README.md +0 -276
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;GAOG;AAEH,+EAA+E;AAC/E,gEAAgE;AAChE,+EAA+E;AAC/E,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACtC,MAAM,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAElC,yCAAyC;AACzC,MAAM,WAAW,GAAG;IAClB,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO;IAC5C,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,kBAA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AAc,EAAE,SAAS,WAAW,CAAC,cAAc,CAAC,YAAY,EAAE,aAAa,WAAW,CAAC,eAAe,GAAG,CAAC,CAAC;QAEzK,iDAAiD;QACjD,kEAAkE;QAClE,sEAAsE;QACtE,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,IAAI,EAAE;YACjC,QAAQ,CAAC,MAAM,EAAE,qDAAqD,CAAC,CAAC;YACxE,IAAI,CAAC;gBACH,MAAM,gBAAgB,EAAE,CAAC;YAC3B,CAAC;YAAC,MAAM,CAAC;gBACP,kCAAkC;YACpC,CAAC;YACD,cAAc,EAAE,CAAC;YACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,+DAA+D;QAC/D,IAAI,CAAC,sBAAsB,EAAE,CAAC;YAC5B,OAAO,CAAC,KAAK,CAAC,uDAAuD,EAAE,KAAK,CAAC,CAAC;YAC9E,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;gBAC1C,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;QAED,oEAAoE;QACpE,yBAAyB,CAAC,KAAK,CAAC,CAAC;QAEjC,cAAc,EAAE,CAAC;QACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
|
package/docs/ADR_CONCEPTS.md
CHANGED
|
@@ -1,12 +1,46 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Decisions & Constraints for AI Development
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Persistent design context — decisions and constraints recorded as structured data — gives AI agents architectural memory across sessions. sqlew makes this zero-effort: plan normally, and hooks capture your decisions automatically.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Why Persistent Design Context Matters
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Research shows that recording design intent dramatically improves LLM code generation:
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
- **22.4% reduction** in overall development time
|
|
10
|
+
- **80% of tasks** completed faster with design intent available
|
|
11
|
+
- **50%+ improvement** in feature-addition and architectural-change tasks
|
|
12
|
+
- **137% increase** in design decision references by final tasks — AI learns to leverage past context more over time
|
|
13
|
+
|
|
14
|
+
> Kitayama, S. (2026). *Rediscovering Architectural Decision Records: How Persistent Design Context Improves LLM Code Generation*. [DOI](https://doi.org/10.36227/techrxiv.177205025.54351571/v1)
|
|
15
|
+
>
|
|
16
|
+
> Blog post: [Recording Design Intent for AI Efficiency](https://blog.sqlew.io/recording-design-intent-for-ai-efficiency)
|
|
17
|
+
|
|
18
|
+
## Key Benefits for AI-Driven Development
|
|
19
|
+
|
|
20
|
+
### Persistent Architectural Memory
|
|
21
|
+
- **Zero context loss** – AI agents remember every architectural decision across sessions
|
|
22
|
+
- **Rationale preservation** – Never forget WHY a decision was made, not just WHAT
|
|
23
|
+
- **Alternative tracking** – Document rejected options to prevent circular debates
|
|
24
|
+
- **Evolution history** – See how decisions changed over time with full version history
|
|
25
|
+
|
|
26
|
+
### Prevent Architectural Drift
|
|
27
|
+
- **Constraint enforcement** – Define architectural rules once, AI follows them forever
|
|
28
|
+
- **Pattern consistency** – AI generates code matching established patterns automatically
|
|
29
|
+
- **Anti-pattern prevention** – Document "what NOT to do" as enforceable constraints
|
|
30
|
+
- **Regression prevention** – AI won't reintroduce previously rejected approaches
|
|
31
|
+
|
|
32
|
+
### Intelligent Decision Discovery
|
|
33
|
+
- **Three-tier duplicate detection** – Gentle nudge (35-44), hard block (45-59), or auto-update (60+) based on similarity score
|
|
34
|
+
- **Similarity detection** – AI identifies duplicate or related decisions before creating new ones
|
|
35
|
+
- **Context-aware search** – Query by layer, tags, or relationships to find relevant decisions
|
|
36
|
+
- **Conflict detection** – Find decisions that contradict or supersede each other
|
|
37
|
+
|
|
38
|
+
### Extreme Efficiency
|
|
39
|
+
- **60-75% token reduction** – Query only relevant decisions instead of reading full files
|
|
40
|
+
- **Millisecond queries** – 2-50ms response times even with thousands of decisions
|
|
41
|
+
- **Scalable architecture** – Perform well with large decision histories
|
|
42
|
+
|
|
43
|
+
## How sqlew Works
|
|
10
44
|
|
|
11
45
|
```mermaid
|
|
12
46
|
flowchart LR
|
|
@@ -31,7 +65,7 @@ flowchart LR
|
|
|
31
65
|
2. Hooks automatically capture decisions
|
|
32
66
|
3. Next session, AI queries past decisions via SQL
|
|
33
67
|
|
|
34
|
-
## Core
|
|
68
|
+
## Core Concepts
|
|
35
69
|
|
|
36
70
|
**Decisions** capture architectural choices with full context:
|
|
37
71
|
- **What** was decided (the decision itself)
|
|
@@ -45,15 +79,13 @@ flowchart LR
|
|
|
45
79
|
- **Coding standards** ("async/await only", "no any types")
|
|
46
80
|
- **Security policies** (authentication patterns, data handling rules)
|
|
47
81
|
|
|
48
|
-
**
|
|
49
|
-
- **File tracking** shows which code was affected by decisions
|
|
82
|
+
**Lifecycle tracking:**
|
|
50
83
|
- **Status evolution** tracks decision lifecycle (draft → active → deprecated)
|
|
51
84
|
- **Auto-capture via Hooks** records decisions automatically from Plan Mode
|
|
52
85
|
|
|
53
86
|
```mermaid
|
|
54
87
|
erDiagram
|
|
55
88
|
DECISION ||--o{ TAG : has
|
|
56
|
-
DECISION ||--o{ FILE : affects
|
|
57
89
|
DECISION {
|
|
58
90
|
string key
|
|
59
91
|
string value
|
|
@@ -70,75 +102,51 @@ erDiagram
|
|
|
70
102
|
TAG {
|
|
71
103
|
string name
|
|
72
104
|
}
|
|
73
|
-
FILE {
|
|
74
|
-
string path
|
|
75
|
-
string action
|
|
76
|
-
}
|
|
77
105
|
```
|
|
78
106
|
|
|
79
|
-
##
|
|
107
|
+
## SQL vs Markdown
|
|
80
108
|
|
|
81
|
-
Traditional
|
|
109
|
+
| Traditional approach (Markdown) | sqlew approach (SQL) |
|
|
110
|
+
|--------------------------------|---------------------|
|
|
111
|
+
| Read entire files | Query specific decisions |
|
|
112
|
+
| Manual duplicate checking | Automatic similarity detection |
|
|
113
|
+
| Text parsing required | Structured, typed data |
|
|
114
|
+
| Linear token scaling | Constant-time lookups |
|
|
115
|
+
| File-based organization | Relational queries with JOINs |
|
|
116
|
+
|
|
117
|
+
### Why SQL?
|
|
118
|
+
|
|
119
|
+
Traditional text-based records force AI to:
|
|
82
120
|
- Read complete files even for simple queries
|
|
83
121
|
- Parse unstructured text to find relationships
|
|
84
122
|
- Manually detect duplicate or conflicting decisions
|
|
85
123
|
|
|
86
|
-
sqlew's **SQL-backed
|
|
124
|
+
sqlew's **SQL-backed decision repository** enables AI to:
|
|
87
125
|
- Query by layer, tags, status in milliseconds (2-50ms)
|
|
88
|
-
- Join decisions with constraints
|
|
126
|
+
- Join decisions with constraints
|
|
89
127
|
- Leverage similarity algorithms to prevent duplicates
|
|
90
128
|
- Scale to thousands of decisions without context explosion
|
|
91
129
|
|
|
92
|
-
**Token efficiency**: 60-75% reduction compared to reading Markdown
|
|
130
|
+
**Token efficiency**: 60-75% reduction compared to reading Markdown files
|
|
93
131
|
|
|
94
|
-
|
|
132
|
+
### Why RDBMS + MCP?
|
|
95
133
|
|
|
96
134
|
**RDBMS (Relational Database)** provides efficient structured queries:
|
|
97
135
|
- **Indexed searches** – Find decisions by tags/layers in milliseconds, not seconds
|
|
98
136
|
- **JOIN operations** – Query related decisions and constraints in a single operation
|
|
99
137
|
- **Transaction support** – ACID guarantees ensure data integrity across concurrent AI agents
|
|
100
|
-
- **Scalability** – Handle thousands of
|
|
138
|
+
- **Scalability** – Handle thousands of decisions without performance degradation
|
|
101
139
|
|
|
102
140
|
**MCP (Model Context Protocol)** enables seamless AI integration:
|
|
103
|
-
- **
|
|
104
|
-
- **
|
|
141
|
+
- **Seamless DB connection** – AI agents access the database through a standardized protocol without direct DB setup
|
|
142
|
+
- **Self-documenting tools** – Tool descriptions teach AI how to use each operation, no manual onboarding needed
|
|
105
143
|
- **Type safety** – Structured parameters prevent errors and guide correct usage
|
|
106
|
-
- **Cross-session persistence** –
|
|
107
|
-
|
|
108
|
-
**Together**: AI agents gain SQL-powered ADR capabilities without managing databases directly.
|
|
109
|
-
|
|
110
|
-
## Traditional vs sqlew ADR
|
|
144
|
+
- **Cross-session persistence** – Decisions survive beyond individual chat sessions
|
|
111
145
|
|
|
112
|
-
|
|
113
|
-
|---------------------------|-----------------|
|
|
114
|
-
| Read entire files | Query specific decisions |
|
|
115
|
-
| Manual duplicate checking | Automatic similarity detection |
|
|
116
|
-
| Text parsing required | Structured, typed data |
|
|
117
|
-
| Linear token scaling | Constant-time lookups |
|
|
118
|
-
| File-based organization | Relational queries with JOINs |
|
|
146
|
+
**Together**: AI agents gain SQL-powered decision capabilities without managing databases directly.
|
|
119
147
|
|
|
120
|
-
##
|
|
148
|
+
## References
|
|
121
149
|
|
|
122
|
-
|
|
123
|
-
-
|
|
124
|
-
-
|
|
125
|
-
- **Alternative tracking** – Document rejected options to prevent circular debates
|
|
126
|
-
- **Evolution history** – See how decisions changed over time with full version history
|
|
127
|
-
|
|
128
|
-
### 🛡️ Prevent Architectural Drift
|
|
129
|
-
- **Constraint enforcement** – Define architectural rules once, AI follows them forever
|
|
130
|
-
- **Pattern consistency** – AI generates code matching established patterns automatically
|
|
131
|
-
- **Anti-pattern prevention** – Document "what NOT to do" as enforceable constraints
|
|
132
|
-
- **Regression prevention** – AI won't reintroduce previously rejected approaches
|
|
133
|
-
|
|
134
|
-
### 🔍 Intelligent Decision Discovery
|
|
135
|
-
- **Three-tier duplicate detection** – Gentle nudge (35-44), hard block (45-59), or auto-update (60+) based on similarity score
|
|
136
|
-
- **Similarity detection** – AI identifies duplicate or related decisions before creating new ones
|
|
137
|
-
- **Context-aware search** – Query by layer, tags, or relationships to find relevant decisions
|
|
138
|
-
- **Impact analysis** – Trace which files are affected by each decision
|
|
139
|
-
- **Conflict detection** – Find decisions that contradict or supersede each other
|
|
140
|
-
|
|
141
|
-
### ⚡ Extreme Efficiency
|
|
142
|
-
- **60-75% token reduction** – Query only relevant decisions instead of reading all ADRs
|
|
143
|
-
- **Millisecond queries** – 2-50ms response times even with thousands of decisions
|
|
144
|
-
- **Scalable architecture** – Perform well with large decision histories
|
|
150
|
+
- Kitayama, S. (2026). *Rediscovering Architectural Decision Records: How Persistent Design Context Improves LLM Code Generation*. [DOI](https://doi.org/10.36227/techrxiv.177205025.54351571/v1)
|
|
151
|
+
- Blog: [Recording Design Intent for AI Efficiency](https://blog.sqlew.io/recording-design-intent-for-ai-efficiency)
|
|
152
|
+
- The concept of Architecture Decision Records was originally proposed by Michael Nygard in 2011.
|
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
# CLI Usage Guide
|
|
2
|
+
|
|
3
|
+
> Command-line tools for database backup, export/import, and cross-database migration
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
sqlew provides CLI commands for database operations that complement the main MCP server. The primary use of sqlew is as an **MCP server** (integrated via `.mcp.json`), but these CLI commands handle:
|
|
8
|
+
|
|
9
|
+
- **Data Export/Import** — JSON-based project data migration (cross-database supported)
|
|
10
|
+
- **SQL Dump** — Full database backup with schema (same-database-type only)
|
|
11
|
+
|
|
12
|
+
## Commands
|
|
13
|
+
|
|
14
|
+
| Command | Purpose | Cross-DB |
|
|
15
|
+
|---------|---------|----------|
|
|
16
|
+
| `db:export` | JSON export (recommended for migration) | ✅ |
|
|
17
|
+
| `db:import` | JSON import (recommended for migration) | ✅ |
|
|
18
|
+
| `db:dump` | SQL dump (backup/restore) | ❌ Same-DB only |
|
|
19
|
+
|
|
20
|
+
### Running CLI Commands
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
# Direct use (global install or npx)
|
|
24
|
+
sqlew db:export backup.json
|
|
25
|
+
sqlew db:import backup.json
|
|
26
|
+
sqlew db:dump sqlite backup.sql
|
|
27
|
+
|
|
28
|
+
# Via npm scripts (within mcp-sqlew project)
|
|
29
|
+
npm run db:export -- backup.json
|
|
30
|
+
npm run db:import -- backup.json
|
|
31
|
+
npm run db:dump -- sqlite backup.sql
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Note**: The first argument determines the mode — `db:export`, `db:import`, `db:dump` enter CLI mode; no argument starts the MCP server.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## JSON Export (`db:export`)
|
|
39
|
+
|
|
40
|
+
### Syntax
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
sqlew db:export [output-file] [key=value ...]
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Options
|
|
47
|
+
|
|
48
|
+
| Option | Description | Default |
|
|
49
|
+
|--------|-------------|---------|
|
|
50
|
+
| `project=<name>` | Export specific project by name | All projects |
|
|
51
|
+
| `db-path=<path>` | Database file path | `.sqlew/sqlew.db` |
|
|
52
|
+
| `config=<path>` | Config file path | Auto-detect |
|
|
53
|
+
|
|
54
|
+
### What Gets Exported
|
|
55
|
+
|
|
56
|
+
- **Master Tables** (filtered to used entries): m_context_keys, m_tags, m_scopes, m_layers, m_projects
|
|
57
|
+
- **Transaction Tables** (all data for selected project): t_decisions, t_decision_context, t_constraints
|
|
58
|
+
- **Junction Tables** (relationships): t_decision_tags, t_decision_scopes, t_constraint_tags
|
|
59
|
+
|
|
60
|
+
### Examples
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
# Export all projects
|
|
64
|
+
sqlew db:export backup.json
|
|
65
|
+
|
|
66
|
+
# Export specific project
|
|
67
|
+
sqlew db:export backup.json project=my-project
|
|
68
|
+
|
|
69
|
+
# Export to stdout
|
|
70
|
+
sqlew db:export project=my-project
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## JSON Import (`db:import`)
|
|
76
|
+
|
|
77
|
+
### Syntax
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
sqlew db:import <source-file> [key=value ...]
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Options
|
|
84
|
+
|
|
85
|
+
| Option | Description | Default |
|
|
86
|
+
|--------|-------------|---------|
|
|
87
|
+
| `<source-file>` | JSON export file path | **Required** |
|
|
88
|
+
| `project-name=<name>` | Target project name | Use name from JSON |
|
|
89
|
+
| `skip-if-exists=true` | Skip import if project exists | `true` |
|
|
90
|
+
| `dry-run=true` | Validate only, don't import | `false` |
|
|
91
|
+
| `db-path=<path>` | Database file path | `.sqlew/sqlew.db` |
|
|
92
|
+
| `config=<path>` | Config file path | Auto-detect |
|
|
93
|
+
|
|
94
|
+
### Import Process
|
|
95
|
+
|
|
96
|
+
1. **Validation** — Checks JSON format, required fields, data types
|
|
97
|
+
2. **Conflict Detection** — Checks if project name already exists
|
|
98
|
+
3. **ID Remapping** — Creates new IDs for all imported data
|
|
99
|
+
4. **Master Table Merge** — Reuses existing tags/scopes by name
|
|
100
|
+
5. **Transaction Import** — Imports with fresh IDs and translated foreign keys
|
|
101
|
+
6. **Junction Table Import** — Restores all relationships
|
|
102
|
+
|
|
103
|
+
### Smart Features
|
|
104
|
+
|
|
105
|
+
- **ID Remapping**: All imported data gets fresh auto-incremented IDs with automatic foreign key updates
|
|
106
|
+
- **Master Table Deduplication**: Tags, scopes reused if they already exist (by name)
|
|
107
|
+
- **Transaction Safety**: All-or-nothing semantics (full rollback on any error)
|
|
108
|
+
|
|
109
|
+
### Examples
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
# Import from JSON
|
|
113
|
+
sqlew db:import backup.json
|
|
114
|
+
|
|
115
|
+
# Import with custom project name
|
|
116
|
+
sqlew db:import backup.json project-name=new-name
|
|
117
|
+
|
|
118
|
+
# Dry-run validation (no actual import)
|
|
119
|
+
sqlew db:import backup.json dry-run=true
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
**⚠️ Important**: Import uses `skip-if-exists=true` by default — it skips if the project name already exists. This is **NOT a backup/restore solution**. Use `db:dump` for backup/restore.
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Cross-Database Migration
|
|
127
|
+
|
|
128
|
+
> **v4.0.2+**: JSON export/import is the **ONLY** supported method for cross-database migrations.
|
|
129
|
+
|
|
130
|
+
### Pre-Migration Checklist
|
|
131
|
+
|
|
132
|
+
- [ ] Backup your current database
|
|
133
|
+
- [ ] Target database is created and accessible
|
|
134
|
+
- [ ] Database credentials are available
|
|
135
|
+
- [ ] Required privileges: SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, INDEX, DROP, REFERENCES
|
|
136
|
+
|
|
137
|
+
### SQLite → MySQL
|
|
138
|
+
|
|
139
|
+
**Step 1: Export from SQLite**
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
sqlew db:export migration-backup.json
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Step 2: Prepare MySQL**
|
|
146
|
+
|
|
147
|
+
```sql
|
|
148
|
+
CREATE DATABASE sqlew_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
149
|
+
CREATE USER 'sqlew_user'@'localhost' IDENTIFIED BY 'your-secure-password';
|
|
150
|
+
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, INDEX, DROP, REFERENCES
|
|
151
|
+
ON sqlew_db.* TO 'sqlew_user'@'localhost';
|
|
152
|
+
FLUSH PRIVILEGES;
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**Step 3: Configure `.sqlew/config.toml`**
|
|
156
|
+
|
|
157
|
+
```toml
|
|
158
|
+
[database]
|
|
159
|
+
type = "mysql"
|
|
160
|
+
|
|
161
|
+
[database.connection]
|
|
162
|
+
host = "localhost"
|
|
163
|
+
port = 3306
|
|
164
|
+
database = "sqlew_db"
|
|
165
|
+
|
|
166
|
+
[database.auth]
|
|
167
|
+
type = "direct"
|
|
168
|
+
user = "sqlew_user"
|
|
169
|
+
password = "your-secure-password"
|
|
170
|
+
|
|
171
|
+
[project]
|
|
172
|
+
name = "your-project-name"
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
**Step 4: Import**
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
sqlew db:import migration-backup.json
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### SQLite → PostgreSQL
|
|
182
|
+
|
|
183
|
+
**Step 1: Export from SQLite**
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
sqlew db:export migration-backup.json
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
**Step 2: Prepare PostgreSQL**
|
|
190
|
+
|
|
191
|
+
```sql
|
|
192
|
+
CREATE DATABASE sqlew_db WITH ENCODING 'UTF8';
|
|
193
|
+
CREATE USER sqlew_user WITH PASSWORD 'your-secure-password';
|
|
194
|
+
GRANT ALL PRIVILEGES ON DATABASE sqlew_db TO sqlew_user;
|
|
195
|
+
\c sqlew_db
|
|
196
|
+
GRANT ALL ON SCHEMA public TO sqlew_user;
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
**Step 3: Configure `.sqlew/config.toml`**
|
|
200
|
+
|
|
201
|
+
```toml
|
|
202
|
+
[database]
|
|
203
|
+
type = "postgres"
|
|
204
|
+
|
|
205
|
+
[database.connection]
|
|
206
|
+
host = "localhost"
|
|
207
|
+
port = 5432
|
|
208
|
+
database = "sqlew_db"
|
|
209
|
+
|
|
210
|
+
[database.auth]
|
|
211
|
+
type = "direct"
|
|
212
|
+
user = "sqlew_user"
|
|
213
|
+
password = "your-secure-password"
|
|
214
|
+
|
|
215
|
+
[project]
|
|
216
|
+
name = "your-project-name"
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
**Step 4: Import**
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
sqlew db:import migration-backup.json
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### MySQL → PostgreSQL
|
|
226
|
+
|
|
227
|
+
**Step 1: Export from MySQL**
|
|
228
|
+
|
|
229
|
+
Configure `.sqlew/config.toml` for MySQL, then:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
sqlew db:export migration-backup.json
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
**Step 2: Prepare PostgreSQL**
|
|
236
|
+
|
|
237
|
+
```sql
|
|
238
|
+
CREATE DATABASE sqlew_db WITH ENCODING 'UTF8';
|
|
239
|
+
CREATE USER sqlew_user WITH PASSWORD 'postgres-password';
|
|
240
|
+
GRANT ALL PRIVILEGES ON DATABASE sqlew_db TO sqlew_user;
|
|
241
|
+
\c sqlew_db
|
|
242
|
+
GRANT ALL ON SCHEMA public TO sqlew_user;
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
**Step 3: Update `.sqlew/config.toml` for PostgreSQL**
|
|
246
|
+
|
|
247
|
+
```toml
|
|
248
|
+
[database]
|
|
249
|
+
type = "postgres"
|
|
250
|
+
|
|
251
|
+
[database.connection]
|
|
252
|
+
host = "localhost"
|
|
253
|
+
port = 5432
|
|
254
|
+
database = "sqlew_db"
|
|
255
|
+
|
|
256
|
+
[database.auth]
|
|
257
|
+
type = "direct"
|
|
258
|
+
user = "sqlew_user"
|
|
259
|
+
password = "postgres-password"
|
|
260
|
+
|
|
261
|
+
[project]
|
|
262
|
+
name = "your-project-name"
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
**Step 4: Import**
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
sqlew db:import migration-backup.json
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Post-Migration Verification
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
# Test MCP server connection
|
|
275
|
+
sqlew --config-path=.sqlew/config.toml
|
|
276
|
+
|
|
277
|
+
# Or use MCP Inspector
|
|
278
|
+
npx @modelcontextprotocol/inspector sqlew
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
Update `.mcp.json` to use the new database:
|
|
282
|
+
|
|
283
|
+
```json
|
|
284
|
+
{
|
|
285
|
+
"mcpServers": {
|
|
286
|
+
"sqlew": {
|
|
287
|
+
"command": "npx",
|
|
288
|
+
"args": ["sqlew", "--config-path", "/path/to/.sqlew/config.toml"]
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
---
|
|
295
|
+
|
|
296
|
+
## SQL Dump (`db:dump`) — Same-Database Only
|
|
297
|
+
|
|
298
|
+
> **v4.0.2+**: `db:dump` supports **same-database-type backup/restore only**. For cross-database migration, use JSON export/import above.
|
|
299
|
+
|
|
300
|
+
### Syntax
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
sqlew db:dump <format> [output-file] [key=value ...]
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### Options
|
|
307
|
+
|
|
308
|
+
| Parameter | Description | Default |
|
|
309
|
+
|-----------|-------------|---------|
|
|
310
|
+
| `<format>` | Target SQL format: sqlite, mysql, postgresql | **Required** |
|
|
311
|
+
| `[output-file]` | Output file path | stdout |
|
|
312
|
+
| `from=<source>` | Source database type | sqlite |
|
|
313
|
+
| `tables=<list>` | Comma-separated table names | All tables |
|
|
314
|
+
| `chunk-size=<n>` | Rows per INSERT statement | 100 |
|
|
315
|
+
| `on-conflict=<mode>` | error, ignore, replace | error |
|
|
316
|
+
| `exclude-schema=true` | Data-only dump (no CREATE TABLE) | false |
|
|
317
|
+
| `db-path=<path>` | SQLite database path | .sqlew/sqlew.db |
|
|
318
|
+
|
|
319
|
+
### Supported Operations
|
|
320
|
+
|
|
321
|
+
| Source | Target | Supported |
|
|
322
|
+
|--------|--------|-----------|
|
|
323
|
+
| SQLite | SQLite | ✅ |
|
|
324
|
+
| MySQL | MySQL | ✅ |
|
|
325
|
+
| PostgreSQL | PostgreSQL | ✅ |
|
|
326
|
+
| Cross-database | Any | ❌ Use JSON |
|
|
327
|
+
|
|
328
|
+
### Examples
|
|
329
|
+
|
|
330
|
+
```bash
|
|
331
|
+
# SQLite backup
|
|
332
|
+
sqlew db:dump sqlite backup.sql
|
|
333
|
+
|
|
334
|
+
# MySQL backup
|
|
335
|
+
sqlew db:dump mysql backup.sql from=mysql
|
|
336
|
+
|
|
337
|
+
# PostgreSQL backup
|
|
338
|
+
sqlew db:dump postgresql backup.sql from=postgresql
|
|
339
|
+
|
|
340
|
+
# Selective table export
|
|
341
|
+
sqlew db:dump sqlite partial.sql tables=m_projects,t_decisions
|
|
342
|
+
|
|
343
|
+
# Ignore duplicates on import
|
|
344
|
+
sqlew db:dump sqlite dump.sql on-conflict=ignore
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
### Importing SQL Dumps
|
|
348
|
+
|
|
349
|
+
```bash
|
|
350
|
+
# SQLite
|
|
351
|
+
sqlite3 your-database.db < dump-sqlite.sql
|
|
352
|
+
|
|
353
|
+
# MySQL
|
|
354
|
+
mysql -e "CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
|
|
355
|
+
mysql mydb < dump-mysql.sql
|
|
356
|
+
|
|
357
|
+
# PostgreSQL
|
|
358
|
+
createdb mydb
|
|
359
|
+
psql -d mydb -f dump-pg.sql
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
### Conflict Resolution
|
|
363
|
+
|
|
364
|
+
| Mode | Behavior |
|
|
365
|
+
|------|----------|
|
|
366
|
+
| `error` (default) | Fails on duplicate keys |
|
|
367
|
+
| `ignore` | Skips duplicate rows |
|
|
368
|
+
| `replace` | Updates existing rows with new values |
|
|
369
|
+
|
|
370
|
+
---
|
|
371
|
+
|
|
372
|
+
## Comparison: JSON vs SQL Dump
|
|
373
|
+
|
|
374
|
+
| Feature | db:export (JSON) | db:dump (SQL) |
|
|
375
|
+
|---------|-----------------|---------------|
|
|
376
|
+
| Format | JSON data only | SQL DDL + data |
|
|
377
|
+
| Schema | Not included | Full schema |
|
|
378
|
+
| Cross-DB | ✅ Yes | ❌ Same-DB only |
|
|
379
|
+
| Use Case | Migration, sharing | Backup/restore |
|
|
380
|
+
| Size | Smaller (~40% reduction) | Larger |
|
|
381
|
+
| Conflict Handling | Smart deduplication | Overwrite or fail |
|
|
382
|
+
| Restore | Skips if exists | Full restore |
|
|
383
|
+
|
|
384
|
+
---
|
|
385
|
+
|
|
386
|
+
## Use Cases
|
|
387
|
+
|
|
388
|
+
### Project Sharing
|
|
389
|
+
|
|
390
|
+
```bash
|
|
391
|
+
# Developer A: Export
|
|
392
|
+
sqlew db:export feature-x.json project=feature-x
|
|
393
|
+
|
|
394
|
+
# Developer B: Import
|
|
395
|
+
sqlew db:import feature-x.json
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
### Multi-Project Consolidation
|
|
399
|
+
|
|
400
|
+
```bash
|
|
401
|
+
# Export from each project
|
|
402
|
+
sqlew db:export /tmp/a.json project=project-a
|
|
403
|
+
sqlew db:export /tmp/b.json project=project-b
|
|
404
|
+
|
|
405
|
+
# Import all to shared database
|
|
406
|
+
sqlew db:import /tmp/a.json
|
|
407
|
+
sqlew db:import /tmp/b.json
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
### Full Database Backup
|
|
411
|
+
|
|
412
|
+
```bash
|
|
413
|
+
# SQL dump (same-DB restore)
|
|
414
|
+
sqlew db:dump sqlite backup-$(date +%Y%m%d).sql
|
|
415
|
+
|
|
416
|
+
# Or simple file copy (SQLite only)
|
|
417
|
+
cp .sqlew/sqlew.db .sqlew/backup-$(date +%Y%m%d).db
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
---
|
|
421
|
+
|
|
422
|
+
## Troubleshooting
|
|
423
|
+
|
|
424
|
+
### Connection Refused
|
|
425
|
+
|
|
426
|
+
```
|
|
427
|
+
Error: connect ECONNREFUSED 127.0.0.1:3306
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
Ensure the database server is running and accepting connections on the specified port.
|
|
431
|
+
|
|
432
|
+
### Authentication Failed
|
|
433
|
+
|
|
434
|
+
```
|
|
435
|
+
Error: Access denied for user 'sqlew_user'@'localhost'
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
Verify username and password in config.toml. Check that the user has proper privileges.
|
|
439
|
+
|
|
440
|
+
### Database Does Not Exist
|
|
441
|
+
|
|
442
|
+
```
|
|
443
|
+
Error: Unknown database 'sqlew_db'
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
Create the database first (see migration steps above).
|
|
447
|
+
|
|
448
|
+
### Permission Denied (PostgreSQL)
|
|
449
|
+
|
|
450
|
+
```
|
|
451
|
+
Error: permission denied for schema public
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
Grant schema privileges: `GRANT ALL ON SCHEMA public TO sqlew_user;`
|
|
455
|
+
|
|
456
|
+
### Import Skipped (Project Exists)
|
|
457
|
+
|
|
458
|
+
```
|
|
459
|
+
Project "my-project" already exists in target database
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
Use `project-name=<new-name>` to specify a different name, or remove the existing project from the target database.
|
|
463
|
+
|
|
464
|
+
### Dry-Run Validation
|
|
465
|
+
|
|
466
|
+
Always test imports with dry-run first:
|
|
467
|
+
|
|
468
|
+
```bash
|
|
469
|
+
sqlew db:import data.json dry-run=true
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
Validates JSON format, project name conflicts, foreign key references, and data type correctness.
|